Results 1 to 8 of 8
  1. #1

    Smile How to show latest posts in the home page in wordpress website?

    I set the front static page as 'page', which is the 'Home' page, and besides the main content in 'Home' page, I would like to add content of the latest posts also. So I made a sub page under 'Home' page, and set the 'posts page' in that sub page under 'Home' page. However, when I view the website, it just shows the main 'Home' page, with no any posts. Could you please tell me how to make the main content and latest posts both appearing in the front page? Thank you!

  2. #2
    Join Date
    Nov 2009
    Location
    Morocco
    Posts
    138
    You can use the is_front_page() conditional :

    Code:
    <?php if( is_front_page() ) :?>
    
    <ul>
    <?php $the_query = new WP_Query( 'showposts=5' ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    <li><?php the_excerpt(__('(more…)')); ?></li>
    <?php endwhile;?>
    </ul>
    
    <?php endif;?>
    the code between UL will show the Recent 5 Posts with Summary... if you would like to show only a List of Posts Title.. Replace all the Code between UL and /UL to :

    Code:
    <?php get_archives('postbypost', '10', 'custom', '<li>', '</li>'); ?>
    Goodluck

  3. #3

    Smile

    Thank you for the code. I added it in the 'Home' page, then I still couldn't see any post other than the main content, except one line of code:

    have_posts()) : $the_query -> the_post(); ?>

    Please tell me what is the reason? Thank you!

  4. #4
    Join Date
    Nov 2009
    Location
    Morocco
    Posts
    138
    hello,

    did you past this code before the Loop !?

  5. #5
    Join Date
    May 2011
    Location
    Netherlands
    Posts
    222
    You could also use the 'Widgets on Pages' plugin to add the 'Recent Posts' widget to your homepage.
    ItsmirHosting UK/EU Shared Hosting • UK & US VPS Hosting • Charity (NFP) Hosting
    Fast, Friendly and Reliable Hosting
    Litespeed Powered • cPanel • CloudLinux • Softaculous • Daily Offsite Backups
    30 Day Money Back Guarantee - 99.9% uptime - 24/7 Dedicated UK support

  6. #6
    Hi, thank you for the information. I just installed a plugin called 'Widgetize pages Light', and I wonder how to make a widget for it? Thank you.

  7. #7

    Thanks for it

    Quote Originally Posted by deadmix View Post
    You can use the is_front_page() conditional :

    Code:
    <?php if( is_front_page() ) :?>
    
    <ul>
    <?php $the_query = new WP_Query( 'showposts=5' ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    <li><?php the_excerpt(__('(more…)')); ?></li>
    <?php endwhile;?>
    </ul>
    
    <?php endif;?>
    the code between UL will show the Recent 5 Posts with Summary... if you would like to show only a List of Posts Title.. Replace all the Code between UL and /UL to :

    Code:
    <?php get_archives('postbypost', '10', 'custom', '<li>', '</li>'); ?>
    Goodluck
    yes i try on this code and it work well

    thanks

  8. #8
    Oh, then maybe I didn't do it in correct way. Is it that I copy and paste the code into the 'Home' page through 'Text' platform, with 'code' brackets?

Similar Threads

  1. Replies: 19
    Last Post: 03-19-2012, 06:15 PM
  2. Replies: 5
    Last Post: 10-09-2011, 10:06 AM
  3. Replies: 5
    Last Post: 07-20-2010, 09:14 PM
  4. WordPress - Latest post on index - Several posts in archives?
    By Jamie Harrop in forum Web Design and Content
    Replies: 1
    Last Post: 02-04-2007, 12:13 PM
  5. [Q]:show bandwidth in the home page ?
    By abdoh2010 in forum Programming Discussion
    Replies: 3
    Last Post: 04-23-2005, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •