Display custom text after the 2nd post?
-
How can I display something AFTER the second post of my blog?
Thank you!
-
is this possible to do?
yes.take a variable $count. if $count == 2 then print your custom text.
My suggestion: Use 2 loops.
First loop will display 2 recent posts, then display your text, then use the next loop to display remaining posts.
can I get an example of this?
After 2nd post, display my content.
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $count = 0; while(have_posts()): the_post(); <!--[YOUR POST CODE HERE]--?> ++$count; if(($count == 2) && $paged== 1){ echo "YOUR CUSTOME TEXT HERE."; } endwhile; ?>
What exactly do you mean by post code?
<h2><?php the_title();?> <p><?php the_content(); ?> etc. which already have. don’t change that. You just add the additional part.
ok, so say I wanted to say “HELLO WORLD” my thing would look like what?
<?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $count = 0; while(have_posts()): the_post(); <!--[YOUR POST CODE HERE]--?> ++$count; if(($count == 2) && $paged== 1){ echo "HELLO WORLD"; } endwhile; ?>
yes but replace this things <!–[YOUR POST CODE HERE]–?> with <h2><?php the_title();?></h2> <p><?php the_content(); ?></p> etc. according to your design. This type of code already have in your index.php file. don’t change that. You just add the additional part which i wrote.
<?php
<!– Additiona part start–>
$paged = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1;
$count = 0;
<!– Additiona part end–>
while(have_posts()): the_post();
<!–[YOUR POST CODE HERE]–?><!– Additiona part start–>
++$count;
if(($count == 2) && $paged== 1){
echo “YOUR CUSTOME TEXT HERE.”;
}
<!– Additiona part end–>
endwhile;
?>how many will i need to add?
The title?
The content?
The date?What else?
this will depend on your requirement tom. According to your design/requirement you will add.
Hope you will understand now.
Sorry chinmoy, I just get a little confused…so if this is my code, what do I need to add?
<?php get_header(); ?> <div id="content"> <script type="text/javascript" src="https://s7.addthis.com/js/250/addthis_widget.js#username=YOUR-ACCOUNT-ID"></script> <?php include(TEMPLATEPATH."/l_sidebar.php");?> <div id="contentmiddle"> <table width="500" border="0" cellspacing="0" cellpadding="5"> </table> <?php if (have_posts()) : while (have_posts()) : the_post();?> <span class="hpfeatured"> <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?> </span><span class="hpfeatured"><a href="<?php the_permalink() ?>" rel="bookmark"></a> <?php endif; ?> </span> <div class="contenttitle"> <table width="500" border="0" cellpadding="3" cellspacing="0"> <tr> <?php if(in_category(array('News','Featured','Features','Indie Focus','Models','Music','Indie','Top 40')) ): ?> <td width="154"><a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" width="150" /></a></td> <?php endif; ?> <td width="500"> <?php if (function_exists('get_cat_icon')) get_cat_icon(); ?> <font size="+1"><?php the_category(', ') ?></font> <font color="black"><?php the_time('F jS, Y') ?></font> <font color="white"><h1><a href="<?php the_permalink() ?>" rel="bookmark"></font> <?php the_title(); ?></h1> </a> <link rel='stylesheet' id='podpress_frontend_styles-css' a href='/updates/wp-content/plugins/podpress/podpress.css?ver=3.0' type='text/css' media='all' /> <h4><?php the_excerpt();?></h4> <?php edit_post_link('Edit','',''); ?> <center><div class="addthis_toolbox addthis_default_style"> <a href="https://addthis.com/bookmark.php?v=250" class="addthis_button_compact">Share</a> <span class="addthis_separator"> </span> <a class="addthis_button_facebook"></a> <a class="addthis_button_twitter"></a> <a class="addthis_button_googlebuzz"></a> <a class="addthis_button_email"></a> <span class="addthis_separator"> </span> <a class="addthis_button_facebook_like"></a> </div></center> </td> </tr> <tr> <td colspan="2"><div style="border-bottom:1px dotted #000; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div></td> </tr> </table> </div> <div class="contenttitle"></div> <?php endwhile; else: ?> </div> <p><?php _e('Sorry, no posts matched your criteria.'); ?> </p> <p> <?php endif; ?> </p> <div class="pmenu"> <p><?php paged_menu(); ?> </p> <p align="center"><a href=" /updates/category/tv/"></a><br /> </p> </div> </div> <?php include(TEMPLATEPATH."/r_sidebar2.php");?> <?php get_footer(); ?>
<?php get_header(); ?> <div id="content"> <script type="text/javascript" src="https://s7.addthis.com/js/250/addthis_widget.js#username=YOUR-ACCOUNT-ID"></script> <?php include(TEMPLATEPATH."/l_sidebar.php");?> <div id="contentmiddle"> <table width="500" border="0" cellspacing="0" cellpadding="5"> </table> <?php if (have_posts()) : $paged = get_query_var('paged') ? get_query_var('paged') : 1; $count = 0; while (have_posts()) : the_post();?> <span class="hpfeatured"> <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?> </span><span class="hpfeatured"><a href="<?php the_permalink() ?>" rel="bookmark"></a> <?php endif; ?> </span> <div class="contenttitle"> <table width="500" border="0" cellpadding="3" cellspacing="0"> <tr> <?php if(in_category(array('News','Featured','Features','Indie Focus','Models','Music','Indie','Top 40')) ): ?> <td width="154"><a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" width="150" /></a></td> <?php endif; ?> <td width="500"> <?php if (function_exists('get_cat_icon')) get_cat_icon(); ?> <font size="+1"><?php the_category(', ') ?></font> <font color="black"><?php the_time('F jS, Y') ?></font> <font color="white"><h1><a href="<?php the_permalink() ?>" rel="bookmark"></font> <?php the_title(); ?></h1> </a> <link rel='stylesheet' id='podpress_frontend_styles-css' a href='/updates/wp-content/plugins/podpress/podpress.css?ver=3.0' type='text/css' media='all' /> <h4><?php the_excerpt();?></h4> <?php edit_post_link('Edit','',''); ?> <center><div class="addthis_toolbox addthis_default_style"> <a href="https://addthis.com/bookmark.php?v=250" class="addthis_button_compact">Share</a> <span class="addthis_separator"> </span> <a class="addthis_button_facebook"></a> <a class="addthis_button_twitter"></a> <a class="addthis_button_googlebuzz"></a> <a class="addthis_button_email"></a> <span class="addthis_separator"> </span> <a class="addthis_button_facebook_like"></a> </div></center> </td> </tr> <tr> <td colspan="2"><div style="border-bottom:1px dotted #000; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div></td> </tr> <!-- Additiona part start--> <?php ++$count; if(($count == 2) && $paged== 1){ echo '<tr> <td colspan="2">YOUR CUSTOME TEXT HERE.</td> </tr>'; } ?> <!-- Additiona part end--> </table> </div> <div class="contenttitle"></div> <?php endwhile; else: ?> </div> <p><?php _e('Sorry, no posts matched your criteria.'); ?> </p> <p> <?php endif; ?> </p> <div class="pmenu"> <p><?php paged_menu(); ?> </p> <p align="center"><a href=" /updates/category/tv/"></a><br /> </p> </div> </div> <?php include(TEMPLATEPATH."/r_sidebar2.php");?> <?php get_footer(); ?>
First keep a backup of your file
ohhhh, that’s cool!!!! Thank you!
Is it possible to display a category like that? Have a certain category with the last 5 posts from that category on the page?
- The topic ‘Display custom text after the 2nd post?’ is closed to new replies.