I am trying to get a image to display in a hidden area, this is a section of code I have copied from another page that someone else made. So it all works, you click the button and the hidden area appears and I can get data from the table I made to display and change the css around that, no problem.
$tmp .= $html->tag('span',$html->tag('h3',
The complete code is below, but the line above is where I am working. This Is the start of the hidden area. What I would like to do is have the img image tag inside the span tag. However all my code does, at this time, is to print/echo the location I have put in the database but not display the image. I am not sure if this is something I have done wrong with where I have put the file, webroot/img/events/tempimg.jpg, what is does print is 'img/events/tempimg.jpg'. From that I take it my image is in the right place just that I have opened the tags in the wrong way. Or would it be better to close the span tag 1st this open the img tag, if so how would I make sure it only appears in the hidden area and not on the main page.
$tmp = $html->tag('strong', $NewDate. " - " . $EventTitle.'<br />');
$tmp .= $html->tag('div', substr($EventLoc, 0, 10).'... <br />', array('class' => 'EventInfo'));
$tmp .= $html->tag('span',$html->tag('h3',
__d('EventsHeader', $e['Team']['name'] . ' Events ', true), array('class' => 'EventInfos'))
.$html->tag('img', $EventImage, array('class' => 'EventHide hide'))
.nl2br($EventInfo . ' testing more......'), array('class' => 'EventHide hide')
);
Many Thanks for any help
Glenn Curtis.
Just in case this helps anyone else, this is now I have now built the tag up, with not using the HTML helper
$tmp .= "<div class=\"EventHide hide\">
<h3 class=\"EventInfos\">" .$e['Team']['name'] . " Events - ". $EventTitle ." - ". $EventLoc ."</h3>
<div class=\"\"><img src=\"$EventImage\" width=\"250\" height=\"200\"/></div>
<span class=\"EventDisplayDate\">When : $DisplayDate</span>
<span class=\"EventDisplayLoc\">Where : $EventLoc</span>
<span class=\"EventDisplayDes\">Description<br/>$EventInfo</span>
</div>";
Glenn.
Related
I want to use the same Loop and Pagination for
index.php , search.php , and archive.php
However, for search.php I want a title "Search Results" to appear before the Loop
and for archive.php I want a title "Archive Page" to appear before the Loop.
Method A
Keep index.php, search.php, and archive.php
And use get_template_part() for navigation and Loop ?
Method B
Just use index.php
but how?
Or is there a simpler method since all I want is to add a title before the Loop?
Simple code for the sake of this example:
index.php
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_excerpt();
endwhile; endif;
?>
code for Pagination
search.php
<h2>Search Results</h2>
code for The Loop
code for Pagination
archive.php
<h2>Archive Page</h2>
code for The Loop
code for Pagination
I don't know the exact structure of your pages, but I would place the code in header.php. Here is my thought on this
The header is common to all of these templates, and I would suspect that you are going to need these titles between your header stuff and the content area
Target pages with conditional tags . Open your header, and right down at the bottom, add something like this
if(is_search()) {
//your title for search page etc
} elseif(is_archive()) {
//your title for archive page
} else {
//display nothing if you don't need to display any custom title
}
Just add the necessary mark up and style accordingly
EDIT
It seems that you are still very new to php. From your comment
Weird. I put <?php if(is_search()) { <h2>Search Results</h2> } ?> at very bottom of header.php but got White Screen. So instead, I put it in index.php and deleted search.php but still White Screen. I tested it in my theme and Twentytwelve. ---------- Can you help me understand... Does less php files equal to a faster website? Is reducing the amount of php files considered best practice? So if index.php , search.php , archive.php uses the same code except for a title "Search Results" and "Archive Page" - is it best practice to simply have one php file and do conditional statements for titles?
Your problem is switching between php and html elements. Whenever you switch from php to html, you need to close your php tag (?>)before your html element. On the otherhand, you need to open a new php tag (<?php) right after your last html element and before your first php element.
Not doing this correctly will lead to a synatx error, which causes a white screen of death.
So in short, your code will need to look like this for it to work properly. Note the php tags
<?php
if(is_search()) { // this part is php
?> <!-- Close php because whe're switching to html -->
<h2>Search Results</h2> <!-- this part is html -->
<?php // open new php tag as we're switching to php again
} elseif(is_archive()) { //same sequence above applied
?>
<h2>Archive Page</h2>
<?php
} else {
//display nothing if you don't need to display any custom title
}
?>
Less php files does not mean a faster website, speed is determined by content, content type, database queries, amount of queries, etc etc. A one page website can be slower than a 10 page website.
What I've done with this code and why I placed it in the header is just to keep the code together. You can split it up as you wish. There is no best practice. What really counts is readability, accesibility, not repeating code over and over, and keeping a proper file system
You could output the title before you start the loop. The contents of the loop would be called using get_template_part(). For example:
if ( have_posts() ) {
// Output the title.
the_title();
// Begin loop.
while ( have_posts() ) {
the_post();
get_template_part( 'loop', 'index' );
}
}
Update: Using just index.php to display a title conditionally, you would do this:
if ( is_search() ) {
// Display the search page title here.
} else if ( is_category() ) {
// Display the category title here.
}
Ref: http://codex.wordpress.org/Function_Reference/get_template_part
I have a polymorphic attachment model between Article and Image (alias for Attachment model) ala https://github.com/josegonzalez/upload. Article hasMany Image. Image is an Attachment.
When the form is submitted via the Article form's save button, everything saves properly, including associated models.
However, I have set up a dynamic display of attached images so that the user can choose which one to use for the article's preview before saving the article. The dynamic image display works (proved by deleting row in phpMyAdmin), but I cannot figure out how to upload and save the associated Image that has been selected without pressing the submit button. I'd like to upload the image immediately upon selection (or upon a button press that does not submit the article, too!
Here is the relevant form section, and the script that eventually results in the display of all associated Images.
<div id='imagesControl'>
<?php
//TODO gotta make this happen live
echo $this->Form->input('Image.0.attachment', array('type' => 'file', 'label' => 'Image'));
echo $this->Form->input('Image.0.model', array('type' => 'hidden', 'value' => 'Content'));
echo $this->Form->input('Image.0.foreign_key', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('Image.0.id', array('type' => 'hidden')); //Thought this would help
?>
<div id='attachedImages'>
</div> </div>
<script>
$(document).ready(function() {
$('#imagesControl').change(function() {window.alert("sometext");
$("#attachedImages").load('../imageDisplay/<?php echo $id ?> #attachedImages',
{id: $(this).attr('id')});
})
.change();
});
</script>
Notably, in the view file '../imageDisplay' that gets rendered, $this->data only contains the div id sent via $(this).attr('id'). I cannot find a variable, anywhere, that contains the file I chose in the input section before the form saves (the file I'm trying to upload and save). It's apparently there, because it does save using $this->Article->saveAll() automagic.
However, I cannot even begin to guess where / when / how I can upload the image and add a row to the attachments table containing the new image's data without submitting the article. I've been stuck for days.
I'm trying to over-ride the default layout template of Categories list within the Module
mod_articles_categories
The reason for that is to be able to display the images associated with each category which is set in the params of each category.
The code that I found to show those images is
json_decode($item->params)->image
But it's not working, any ideas?
The "official" way would be to use something like this within the foreach ($list as $item) :
<?php
$params = new JRegistry();
$params->loadString($item->params);
$image = $params->get('image');
if ($image) : ?>
<img src="<?php echo $image; ?>" />
<?php endif; ?>
But you code should work as well. At least it does when I tested it locally. The code I posted would allow you to set a default value for the param. Like $params->get('image', 'foo/bar.png');. Other than that it does about the same.
Hi all creating a link that when you click it, it opens a new window. I was wondering if it's possible to restrict the size of the window opening?
this is the code I have for the link that opens the window
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array('target'=>'_blank', 'escape'=>false)); ?>
You can do this, but only with Javascript.
Raw code would be something like:
Text Link
The only parameters you really need are width and height, but you might find the others useful too. If not, just delete them. If the user doesn't have javascript, it'll just open the link normally.
To do it with html helper, pass your javascript through to the onClick array key:
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array(
'target'=>'_blank',
'escape'=>false,
'onClick'=>"window.open('/pages/home', 'windowname','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=290'); return false;"
)); ?>
PS - you can read up on the window.open method here: http://www.w3schools.com/jsref/met_win_open.asp
So. I created a custom WordPress taxonomy. And I have multiple posts that use that taxonomy with various terms under this taxonomy. What I'm trying to get WordPress to do is spit out all the taxonomy terms from all the posts. I'm going to stick each of them inside a rel="" tag so I can get a little fancy with jQuery.
I accomplished this with plain old WordPress tags like this:
<?php
$posttags = get_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<label><input type="checkbox" rel="' . $tag->slug . '">' . $tag->name .
'</label>';
}
}
?>
It works perfectly. Makes a checkbox and label for each tag. But now I need these custom taxonomy terms instead.
I've been fiddling with:
$categories = get_terms('Year-taxonomy', 'orderby=name&hide_empty=0');
$cats = object_to_array($categories);
Not working so far. Am I on the right track?
Not well versed with the WordPress Codex, but managed to figure it out.
First off there's the function:
function get_custom_terms($taxonomies, $args){
$args = array('orderby'=>'asc','hide_empty'=>true);
$custom_terms = get_terms(array($taxonomies), $args);
foreach($custom_terms as $term){
echo 'Term slug: ' . $term->slug . ' Term Name: ' . $term->name;
}
}
Then the function call wherever need:
<?php get_custom_terms('your_custom_taxonomy_name'); ?>
Function call must be same as function name:
get_custom_terms('your_custom_taxonomy_name');