[resolved] Change style of stories in category list (10 posts)

  1. ad4mlaz
    Posted 3 years ago #

    I want to change the style of how stories are printed in the category list. Right now, the code is:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    so all of the posts that are printed have the same style. How can I make the category page for example:
    The first two 'featured stories' are printed with a certain style then, the stories below are printed on the page with a different style. This same style would also have to work when you go forward or back pages, listing more stories in the category.

    If you need any more information, just ask.

  2. Paul Kaiser
    Posted 3 years ago #

    Howdy Adam,
    Let's give it a shot, based off your code above.

    if( have_posts() ) {
    $counter = 0;
    while( have_posts() ) {
    // check to see if we are on one of the first 2 items
    if( $counter < 2 ) {
    // do whatever in your theme for the design of your first 2 posts
    } else {
    // do whatever you want for posts after the 2nd one
    } // end while
    } // end if

    Anyway, give that a shot, and let me know if you have questions.
    Take care,

  3. ad4mlaz
    Posted 3 years ago #

    This works great. Now, I want to skip stories 3,4,5. I am just going to make an extra entry in the if statement to do nothing for these stories. I want them to display with their own style in a sidebar. How do I get stories 3,4,5 on any given page?

    If you need any more information, just let me know.

    Thank you,

  4. Paul Kaiser
    Posted 3 years ago #

    Glad you're headed in the right direction.

    1. Do you have your blog set up to show "newest 5 posts," then, in "Settings > Reading?" I'm assuming so, but needed to check.
    2. You want 3,4,5 to show up in a sidebar, in a widget, then?
    -- Do they HAVE to be in a widget, or is it okay if they just show up in the sidebar by any means?
    3. What theme are you currently using?

    While you can search on the internet for what you want (mostly) by searching for "access posts from outside the loop," almost all of these approaches you find are inefficient, requiring a new set of queries.

    If you would please answer my questions above, I'd like to show you how to do this WITHOUT all those extra queries.


  5. ad4mlaz
    Posted 3 years ago #

    1. Blog pages show at most 10 posts
    Syndication feeds show the most recent 10 items

    2. Widget would be nice.

    3. Currently using Organic News http://organicthemes.com/demo/news/

  6. Paul Kaiser
    Posted 3 years ago #

    Oops, I forgot to ask question number 4:
    What page(s) do you want to do this special situation for?
    Is it a page where you can use a specific Page Template?
    Or, is it on the Home Page?

    This will affect the best approach to the solution.


  7. ad4mlaz
    Posted 3 years ago #

    It is on the category pages (category.php)

  8. ad4mlaz
    Posted 3 years ago #

    How would I do this with an additional query?


  9. Paul Kaiser
    Posted 3 years ago #

    Hi again,
    Here is my recommendation:
    1. skip stories 3, 4, 5 in your main loop (you already know how to do that above.)
    2. In your sidebar, include a widget or custom code that does a query for stories 3, 4, and 5.

    Here's how to do a custom query:

    In your query, you'll need to use the "offset" parameter so you can get just 3, 4, 5:

    Good luck!

  10. ad4mlaz
    Posted 3 years ago #

    Thanks! Perfect

Topic Closed

This topic has been closed to new replies.

About this Topic