Tip: Customize Main Page Loop Actions, Wordpress
I wanted to only show full contents for the first 5 posts and display titles for the rest - regardless of how many is set as the total number in the admin console. Came up with two VERY simple lines of code to use in the wordpress template. Thought I’d share.
After this line of code if (have_posts()) : in the Main Index template…
//Insert this piece of code to set display for the first 5 posts:
<?php while (have_posts()) : the_post(); ?>
<?php if ($wp_query->current_post <= 4) { ?>
ENTER YOUR TEMPLATE CODE TO DISPLAY FULL CONTENT
<?php }; ?>
<?php endwhile; ?>
“4″ sets the number of posts to 5 since the counter starts with 0.
Change it to anything your heart desires.
//Insert this right after the last code for the rest:
<?php while (have_posts()) : the_post(); ?>
<?php if $wp_query->current_post > 4)) { ?>
ENTER YOUR TEMPLATE CODE TO DISPLAY TITLE
<?php }; ?>
<?php endwhile; ?>
That’s it. Simple!!


Leave a Comment Here
(send me a private message)