Title: Prblems in advanced loop customizing
Last modified: August 19, 2016

---

# Prblems in advanced loop customizing

 *  [maorb](https://wordpress.org/support/users/maorb/)
 * (@maorb)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/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
       		          </div>
       			    <?php $count++ ?>
   
       			 <?php   } else {  // all other items  ?>   
   
                               <div class="regular-item">
                       		some code for showing other items
       			</div>
       		         <?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)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196776)
 * Use [query_posts()](http://codex.wordpress.org/Template_Tags/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.
 *  Thread Starter [maorb](https://wordpress.org/support/users/maorb/)
 * (@maorb)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196787)
 * 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?
 * Thanks
 *  Thread Starter [maorb](https://wordpress.org/support/users/maorb/)
 * (@maorb)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196790)
 * 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…
 *  Thread Starter [maorb](https://wordpress.org/support/users/maorb/)
 * (@maorb)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196845)
 * Anyone has an idea?
 * Thnaks
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196861)
 * There is an example in the codex that explains how to deal with pagination.
 *     ```
       <?php
       global $wp_query;
       query_posts(
               array_merge(
                       array('cat' => -19),
                       $wp_query->query
               )
       );
       ?>
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Prblems in advanced loop customizing’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/prblems-in-advanced-loop-customizing/#post-1196861)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
