• Resolved thetanooki

    (@thetanooki)


    So I’m wondering if it’s possible to change how posts are displayed on the main index of my blog. I have it set to show the first 20 excerpts (not full posts, just excerpts) with thumbnails (WP Post Thumbnails), and I’m curious if it’s possible to have only the first 8 or so show excerpts while everything after that is simply just headlines.

    I’m wondering, since I’ve seen other code examples where you can change how the first or last of a series can have special stylings using CSS, and I’m curious if this or a similar method would make what I’m trying to do possible.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi

    add this line before the WordPress loop

    $i=0;
    (Loop ..... )
    <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>

    add this after the line with while
    $i++;

    now you can surround the code that displays your thumbnails with

    <?php if ($i < 9) { ?>
       ======  display thumbnail =====
    <?php } >?

    That thumbnail code will only execute on the 1st 8 posts

    Thread Starter thetanooki

    (@thetanooki)

    That works, thanks a ton!

    On a side note, what would be the proper way/syntax to turn this into an if/else in case I want to customize the look of the headline-only part a little more?

    not clear on what you want to do – explain in more detail

    Thread Starter thetanooki

    (@thetanooki)

    For example, here’s what a normal excerpt looks like:

    Title Title Title Title Title Title Title

    ——— by Author in Category *twitter link*
    | |
    | thumb | Excerpt Excerpt Excerpt Excerpt Excerpt
    | | Excerpt Excerpt Excerpt Excerpt Excerpt
    ——— ##views | ##comments

    Now, by adding your code, I can easily remove parts in the middle. Since the thumbnails are tied to the call to list the categories, that needs to go, but I’d like to reformat the non-thumb posts so it looks more like this:

    Title Title Title Title Title Title Title
    by Author – ##comments – *twitter*

    To do that, I assume I’d basically need to rewrite part of the code, albeit in the simplified form, and it would simply be inside an “else” statement.

    oh i see.

    yes, you can certainly conditionally display other parts of the post sections.

    if you are going to have a few conditional sections its better programming practice to do it like this

    <?php  // are we displaying a top post?
       $top_posts = ($i < 9) ? true : false;
       if ($top_posts) { ?>
       ======  display thumbnail =====
    <?php } >

    Then in the other sections:
    if ($top_posts) { do something } ?>

    reason: If you use ($i < 9) in a number of places if you later change 9 it to 8 or 11, you have to update every occurrence of 9, and its easy to miss one. If you use $top_posts you only have to update 9 in one place and all the other references update automatically.

    Thread Starter thetanooki

    (@thetanooki)

    That makes sense. Thanks a ton for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Is is possible to switch display format after a certain # of posts?’ is closed to new replies.