WordPress.org

Ready to get started?Download WordPress

Forums

index page to display custom posts (6 posts)

  1. nhall
    Member
    Posted 8 years ago #

    I have been reading the support forums and have found out how to just show excerpts on the index page. I think that the <!-- more --> option is extremely powerful. I like the idea of getting to decide where each entry is cut off. I have this implemented on my local machine. I have changed the default features so that only the last two posts are shown on the index page. What I want to do is to give the two posts shown on the index page different IDs or classes. I want to give them completely seperate styles.
    I want the most recent post to be the most important therefore styled differently and taking up the most real estate. Then I want the 2nd most recent post styled a little differently with less emphasis and then a list of the other recent entries.

    Here is a link to a graphical explanation.

    Thank you for any help.

  2. Ming
    Member
    Posted 8 years ago #

    Method 1: This uses just 1 loop and allows you to style your first, second and then all other posts separately.

    <?php if (have_posts()) : ?>

    <?php // Initialize the counter
    $counter = 0;
    ?>

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

    <?php if ($counter == 0) { ?>

    // Display post #1 this way

    <?php } elseif $counter == 1 { ?>

    // Display second post this way

    <?php } else { ?>

    // All other posts are displayed like this

    <?php } ?>

    <?php // Add 1 to the counter
    $counter++;
    ?>

    <?php endwhile; ?>

    // What you want displayed after the loop has run

    <?php else : ?>

    // What you want displayed if no posts are found

    <?php endif; ?>

  3. Ming
    Member
    Posted 8 years ago #

    Method 2: Use multiple loops in your page. This is sometimes easier if your posts don't directly follow each other in the source code.

    The codex has a page about using multiple loops and you'll also want to look at the Query Posts page for information on how to limit each query to just the specific posts you want.

  4. nhall
    Member
    Posted 8 years ago #

    Ming,
    Thank you so much for the great links. I will read up, it looks like they will be able to help with any queationa that i might have.

    Thanks again

  5. nhall
    Member
    Posted 8 years ago #

    Here it is a month later and I am still trying to figure out the same problem. I like the two different methods that Ming discussed, but here is the question. If I incorporate a second loop, will this create problems down the road. Lets say that I get this finished and then the release an new wordpress. Will I just be able to upgrade?

    As for the difference between the two methods. When you say that it can be better if the posts don't directly follow eachother in the source code, I just want to make sure I understand. You mean that if in my layout I have a something like a div element separating the different posts, I will need two loops?

    I will probably come back with some php syntax questions.

    Thanks

  6. nhall
    Member
    Posted 8 years ago #

    I have tried to develop one loop that will display the posts differently. Here is the code that I have so far:
    http://pastebin.com/383424

    When I test this I get the following error:
    "Parse error: parse error, expecting `'('' in /wp-content/themes/single/index.php on line 33"

    Line 33 on my index.php is equal to line 15 in my pastebin.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags