Support » Fixing WordPress » Prblems in advanced loop customizing

  • Hi all,

    I use this loop for displaying the last posted item as the “featured” item (without using a special category for featured), and then all other items in regular order.
    This is the code, which is working very well:

    <?php if (have_posts() ) {  // if is 1st item on home page
                         $count = 0;
                             while (have_posts()) : the_post();
                             if (is_front_page() && !is_paged() && ($count == 0)  ) { ?>  
                              <div class="mainitem">
    				some code for the main item
    			    <?php $count++ ?>
    			 <?php   } else {  // all other items  ?>   
                            <div class="regular-item">
                    		some code for showing other items
    		         <?php }  endwhile; ?>
            <?php } ?>
    		<!-- End items -->

    Now, I want to have some categories excluded from the loop, and to show them in the sidebar. Suppose I want to exclude category id #19, I tried to add
    if (in_category(19)) continue;
    but then I’ve got weired things happening, such as displaying only 1 item per page, or haveing the 1st page empty and items only starting at page 2.

    I’m desparated here, trying for hours to find a good syntax and way to do that exclusion. What am I doing wrong in here?

    Or maybe the whole of my loop concept is wrong, and I should not use this way to display the featured/last post ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Use query_posts() to exclude the posts with categories you don’t want, then you no longer have to worry about dealing with them in your loop.

    When I built this loop first, couple of months ago (then I didn’t need to exclude categories) I tried to use query_posts(), but then I’ve had problems with the main loop not showing well the last item in the main css class and the others in the other css class.

    Since this loop creates the last item posted with count = 0 and show the special class only in the front_page().
    When then tried to use the query_posts() I had to use offset=n and then I had problems with the pagination..
    So I’m not sure that going back to query_posts() will be a good idea for me in this case.
    Isn’t it?
    Maybe there is another idea?


    Yes, as I remember, trying now again to use query_posts(“cat=-19”); just before my loop – I’ve got on the 1st and 2nd pages the same posts, and also the class for the main posts being displayed on the 2nd page, which is not whatt I want…

    Anyone has an idea?


    There is an example in the codex that explains how to deal with pagination.

    global $wp_query;
                    array('cat' => -19),
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Prblems in advanced loop customizing’ is closed to new replies.