Is there any reason why this is happening due to the following code? All that gets displayed is the variable , i.e the image.
<?php $featured_image = the_post_thumbnail();?>
<?php if (is_page(7) || is_page(12))
echo '<div class="featured_image">' . $featured_image . '</div>'
?>
<?php
$featured_image = the_post_thumbnail();
if (is_page(7) || is_page(12)) {
echo '<div class="featured_image">' . $featured_image . '</div>';
}
?>
The function itself echos the img: http://codex.wordpress.org/Function_Reference/the_post_thumbnail
try:
<?php
if ( has_post_thumbnail() && (is_page(7) || is_page(12))) {
echo '<div class="featured_image">';
the_post_thumbnail();
echo '</div>';
}
?>
What you are seeing is the return value of the echo function.
Related
I want to insert php code in between tabby tabs shortcodes.
I am using a plugin tabby tab for tab view and have added this code in my theme template:
<?php echo do_shortcode('[tabby title="Gallary Name"]
name content
[tabby title="Images"]
[tabbyending]'); ?>
I want to use a custom fields gallery under images tab using code like this:
<?php echo do_shortcode('[tabby title="Gallary Name"]
name content
[tabby title="Images"]
<?php
$i = 0;
$images = get_field('vil_pics');
if( $images ): ?>
<div>
<ul>
<?php foreach( $images as $image ): ?>
<li<?php if ( $i % 3 == 0 ) echo ' class="break"' ?>>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a><p>.</p>
</li>
<?php endforeach; ?>
</ul></div>
<?php endif; ?>
[tabbyending]'); ?>
This code is not working, it's showing a blank page. How can I fix this?
Tabby uses a global variable to track what's going on, so I think either one of these will work. The first one is a little more straightforward, but the second one will definitely work.
Option 1: output everything in order:
echo do_shortcode( '[tabby title="Gallery Name"] name content' );
echo do_shortcode( '[tabby title="Images"]' );
// your php code as-is
$i = 0;
$images = get_field('vil_pics');
if( $images ): ?>
<div>
<ul>
<?php foreach( $images as $image ):
$i++ ?>
<li<?php if ( $i % 3 == 0 ) echo ' class="break"' ?>>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a><p>.</p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;
echo do_shortcode( '[tabbyending]' );
or Option 2: save everything to a variable and output it all at once:
$output = '';
$output .= '[tabby title="Gallery Name"] name content';
$output .= '[tabby title="Images"]';
$i = 0;
$images = get_field('vil_pics');
if ( $images ) {
$output .= '<div><ul>';
foreach( $images as $image ) {
$i++;
$li_class = ( $i % 3 == 0 ) ? ' class="break"' : '';
$output .= '<li' . $li_class . '>';
$output .= '<a href="' . $image['url'] . '">';
$output .= '<img src="' . $image['sizes']['thumbnail'] . '" alt="' . $image['alt'] . '" />';
$output .= '</a><p>.</p></li>';
}
$output .= '</div></ul>';
}
$output .= '[tabbyending]';
echo do_shortcode( $output );
Note that I didn't see anything increasing $i so I added that. Everything else is as-is.
I am trying to modify the module template code to add an anchor to the title of each module. I have extremely limited PHP knowledge, so any guidance would be very helpful.
I've found posts for doing this with articles, but the code appears to be very different for modules.
This is the code that is in my module template.
function modChrome_basic($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<?php echo $module->content; ?>
<?php endif;
}
function modChrome_standard($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<div class="rt-block <?php if ($params->get('moduleclass_sfx')!='') : ?><?php echo $params->get('moduleclass_sfx'); ?><?php endif; ?>">
<div class="module-surround">
<?php if ($module->showtitle != 0) : ?>
<div class="module-title">
<?php
echo '<h2 class="title">';
if (preg_match("/icon[-]{1,}/i", $params->get('moduleclass_sfx'))) :
echo '<span class="title-icon ' .getIconClass($params->get('moduleclass_sfx')). '"></span>';
endif;
echo $module->title;
echo '</h2>';
?>
</div>
<?php endif; ?>
<div class="module-content">
<?php echo $module->content; ?>
</div>
</div>
</div>
<?php endif;
}
This is the code I tried
if( strlen($this->item->params->get('title')) > 0 ) {
echo '<a name="'.$this->item->params->get('title').'"></a>';
}
I also tried
if( strlen($module->item->params->get('title')) > 0 ) {
echo '<a name="'.$module->item->params->get('title').'"></a>';
}
Joomla has an easy way to customize the module appearance.
You have to use a Custom module chrome.
You have to create a modules.php file under /templates/TEMPLATE_NAME/html/modules.php.
Inside this file you have to put:
<?php
function modChrome_custom( $module, &$params, &$attribs ) {
echo '<div id="' .$params->get( 'moduleclass_sfx' ) .'" >';
if ($module->showtitle)
{
echo '<h' .$headerLevel .'>' .$module->title .'</h' .$headerLevel .'>';
}
echo '<div class="module_content">';
echo $module->content;
echo '</div>';
echo '</div>';
}
?>
In the code above the module id getting moduleclass_sfx value. You could change it and set another module variable.
In order to use this appearence you have to set the appropriate style to the template module calls like: <jdoc:include type="modules" name="user1" style="custom" />
If you want to use another style name you have to change the function from modChrome_custom to modChrome_NEWSTYLE.
Good Luck!
How do i print INSIDE the defined tag?
When it ouputs this code, the_title() gets printed OUTSIDE (before) the h1 tag..
My code is:
<?php
if ( '' != get_the_post_thumbnail() ) {
print '<p>HEY</p>';
}
else {
print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">', the_title() ,'</h1></div>';
}
?>
i have already tried:
<?php
if ( '' != get_the_post_thumbnail() ) {
print '<p>HEY</p>';
}
else {
print '<div class="page-header row full"><h1 class="page-title" itemprop="headline">'. the_title() .'</h1></div>';
}
?>
What am i doing wrong?
Thanks
You could do like below:
<?php if ( '' != get_the_post_thumbnail() ): ?>
<p>HEY</p>
<?php else: ?>
<div class="page-header row full"><h1 class="page-title" itemprop="headline"><?php the_title(); ?></h1></div>
<?php endif; ?>
Or use get_the_title()(which returns the title value) instead.
Try print "....".get_the_title().".....";
The methods "the_xxxx" print the value, the methods "get_the_xxx" returns the value.
try echo instead of print
echo - can output one or more strings
print - can only output one string, and returns always 1
I'm using Foundation for a wordpress theme and I need to wrap two posts into one div with class of 'row'. The thing is I need to put div class="row" before the first post closing the the second post with div and it should repeat with every new posts.
Here is my code:
<?php query_posts( 'cat=2&showposts=9&orderby=date&order=DESC' ); ?>
<div <?php post_class('small-12 medium-6 large-6 columns') ?> id="post-<?php the_ID(); ?>">
<?php echo '<a href="', get_permalink(), '">';
if ( has_post_thumbnail() ) {the_post_thumbnail();}
else { echo '<img src="', get_template_directory_uri( 'template_directory' ), '/images/thumb-default.png','" alt="" />'; }
echo '</a>';
?>
<h3><?php the_title(); ?></h3>
<p><?php echo get_excerpt(); ?></p>
</div>
something like this i think
<?php
$count = 1;
$outputstring = "";
ur while loop
if ( $count % 2 != 0 )
{
$outputstring .= " <row div>";
}
$outputstring .= "<div" . post_class('small-12 medium-6 large-6 columns'). ' id="post-'. the_ID() .'>';
YOUR OUTPUT CODE HERE
if ( $count % 2 == 0 )
{
$outputstring .= " </end row div>";
}
$count++;
END your while loop
echo $outputstring; /// here is where u output the WHOLE thing outside of your loop
?>
I'm not entirely sure why this isn't working. But this piece of code does not work.
<?php
foreach ( $gallery_ids as $gallery ) {
echo '<div class="tgallery" rel="'.$gallery['gid'].'"><?php echo do_shortcode("[nggallery id='.$gallery['gid'].']"); ?></div>';
}
?>
I was guessing that maybe I'm putting the wrong quotes in the wrong place.
All the parts seperately work, as in :
I can display the 'gid' value with echo $gallery['gid']
I can make the div tags appear with the appropriate rel
I can, by itself, make <?php echo do_shortcode("[nggallery id=3]"); ?> work.
I just can't make the entire thing appear together.
You're mixing interpolated php and html, placing "<?php echo" inside what's already php.
<div class="tgallery" rel="<?php echo $gallery['gid'];?>">
<?php echo do_shortcode('[nggallery id="'.$gallery['gid'].'"]'); ?>
</div>
Why you put <?php ?> inside your echo ?
<?php
foreach ( $gallery_ids as $gallery )
{
echo '<div class="tgallery" rel="'.$gallery['gid'].'">'.do_shortcode('[nggallery id='.$gallery['gid'].']').'</div>';
}
?>
The issue
Pick either string concatenation or opening/closing PHP for HTML. You cannot combine both as you have done above.
echo '<div class="tgallery" rel="'.$gallery['gid'].'">
<?php echo do_shortcode("[nggallery id='.$gallery['gid'].']"); ?>
</div>';
The second line of code above does not belong inside a string as code in between the <?php ... ?> will not be parsed by PHP when it is contained in a string.
Solutions
Concatenation
I have fixed your code to use concatenation below:
foreach ( $gallery_ids as $gallery ) {
$shortcode = do_shortcode("[nggallery id={$gallery['gid']}]");
echo '<div class="tgallery" rel="' . $gallery['gid'] . '">' . $shortcode . '</div>';
}
Opening and closing PHP
This is how you would do it using PHP "templating":
<?php foreach($gallery_ids as $gallery ): ?>
<div class="tgallery" rel="<?php echo $gallery['gid']; ?>">
<?php echo do_shortcode("[nggallery id={$gallery['gid']}]"); ?>
</div>
<?php endforeach; ?>
You are already "in" php, so your opening tag is causing the problem:
<?php echo do_shortcode("[nggallery id='.$gallery['gid'].']"); ?>
It should be something like:
echo '<div class="tgallery" rel="'.$gallery['gid'].'">' . do_shortcode('[nggallery id='.$gallery['gid'].']') . '</div>';
<?php
foreach ( $gallery_ids as $gallery ) {
echo "<div class=\"tgallery\" rel=\"{$gallery["gid"]}\">". do_shortcode("[nggallery id=\"{$gallery["gid"]}\"]") ."</div>";
}
?>
try this....
<?php
foreach ( $gallery_ids as $gallery ) {
echo '<div class="tgallery" rel="'.$gallery['gid'].'">'.do_shortcode("[nggallery id=".$gallery['gid']."]").'</div>';
}
?>
you have inside a php statment
Try Notepad then it will colour code your php code, so you can clearly see what quotes etc you have wrong