Wordpress First Post Only On Frontpage
12:58 am on December 25th, 2007 | Hits: 973
Posted in Tips & Tricks


If you check out my theme, you would notice that only the first latest post of my blog is expanded and showed and the rest of the post follows with summary. Some people would just love to have this kind of theme as it’s more clean when viewed. Here is the hack on how i did it. It’s not the cleanest code and im pretty sure there are better ways to do it, but it just works. Editing should be done to index.php file.

Basically the concept is to create multiple loop with post limitations and offset. Open up index.php and follow this code. The code below is used to display only the 1st post of your blog and it’s up to you to design it.

<?php if (is_home() && !is_paged() ) { ?>
<?php query_posts('showposts=1'); ?>

<?php if (have_posts()) : ?>
	<?php while (have_posts()) : the_post(); ?>

        <!--- The style for your blog post
                which is full! (The 1st Post) --->

<?php endwhile; ?>
<?php endif; ?>
<?php } ?>


After the code we follow up with another loop where you can specify how the remaining posts are displayed. You can display the title and also the excerpt like how i have displayed on my site.

<?php if (is_home() && !is_paged() ) { ?>
<?php query_posts('showposts=10&offset=1'); ?>
<?php if (have_posts()) : ?>
	<?php while (have_posts()) : the_post(); ?>

        <!--- The style for your remaining blog posts
                (Better to use the_excerpt(); ) --->

    <?php endwhile; ?>
<?php endif; ?>
<?php } ?>

From the above code, we can simply change a few variables.

<?php query_posts('showposts=10&offset=1'); ?>

In the code above you could change the ’showpost’ section to the number of remaining post you want to show on the frontpage and the ‘offset’ is used to skip how many posts before displaying the list of posts.

If you are having problem to display your posts inside category or if you use index.php as your category template, then adding this code in index.php might help.

<?php if (!is_home()) { ?>
<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <!--- The style for your category posts --->

    <?php endwhile; ?>
<?php endif; ?>
<?php } ?>

Basically that is about it. You may adopt this code into your theme and it should work fine, i tested it on Wordpress 2.1x without problem. Please take note that this code might not work with all themes and also might cause conflict with some themes and plugins.





Related Posts

08.08.08 I Have Been Updated! - Posted @ 3:02 am on August 8th, 2008
Remove Unwanted Space From A Form Element - Posted @ 2:30 pm on May 7th, 2009
I Have A Lifelog On My Blog! - Posted @ 3:58 am on February 21st, 2010


Recommended



Comments

Leave a comment:

Your comment :

 
About Me

I'm ramesh from Perak, Malaysia. Blogging is my hobby hence this blog is my second home to share my life, interests and etc.



Blog Menu



Recent Friends



 

page made and maintained by mesh