WordPress.org

Ready to get started?Download WordPress

Forums

1 post on index followed by 10 recent title: Possible? (5 posts)

  1. FionaDixit
    Member
    Posted 9 years ago #

    Hello,

    Is there a way to have 1 main post on the front page followed by 10 recent titles so it looks a little like this,

    Latest Title
    some text here and so on.

    01:05:2005 - title here
    01:05:2005 - title here
    01:05:2005 - title here
    01:05:2005 - title here
    01:05:2005 - title here
    and so on.

    Can it be done?

    Thanks
    F

  2. Kafkaesqui

    Posted 9 years ago #

    First, create a home.php for your theme. Just make a copy of index.php and name it home.php.

    Then, replace The Loop in home.php with this:

    <?php
    // First post
    $posts = get_posts('numberposts=1');
    foreach ($posts as $post) :
    setup_postdata($post);
    ?>

    <!-- Place here any template tags/html/etc. you want to in The Loop for your latest post. Based on your query: -->

    <h3 class="post-title"><?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_content(); ?>

    <?php endforeach;
    // Next ten posts
    get_posts('numberposts=10&offset=1');
    foreach ($posts as $post) :
    ?>

    <?php the_time('m:d:Y'); ?> - <a href="<?php the_permalink(); ?>"><?php the_title() ?></a>

    <?php endforeach; ?>

    -------------------------------------

    Info on the get_posts function:

    http://wiki.wordpress.org/get_posts

    (Note that 'category' is supported in 1.5.)

  3. FionaDixit
    Member
    Posted 9 years ago #

    Thank you so muc Kafkaesqui :)

    Just what I wanted.
    F

  4. RustIndy
    Member
    Posted 9 years ago #

    Technically that works, but it causes the Loop to be run twice and an extra page to be created - not always desirable.

    When I needed to do this, I just modified the index.php to set bIsFirstPost = true at the top, then changed the Loop to show the_content if that value is true, and the_excerpt if the value is false. Of course, you have to set bIsFirstPost = false at the end of the Loop ;)

    Doing it this way means home.php is available for something else and the Loop is only run once.

  5. KarlB
    Member
    Posted 9 years ago #

    Hi RustIndy,

    I might be interested in that.

    Have you any code examples? Can't quite get my head around what you do :)

    Thanks
    Karl

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.