Title: Changing the loop
Last modified: August 21, 2016

---

# Changing the loop

 *  Resolved [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/)
 * Hi!
 * I have the code below that is set to pick up different cathegories. How can I
   change it to only search for category id=81 for example? I have tried different
   possibilities but can´t get this to work…
 * Thanks
    /Karin
 * _[please mark any posted code – [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)–
   the code below is partially broken by the forum parser]
 *     ```
       <?php $current_num = $wp_query->current_post + 1; ?>
   
       <?php if ( $wp_query->current_post == 0 ) {
       	echo '
       <li><ul class="shop-block-list">';
       } elseif ( $wp_query->current_post % 3 == 0 ) {
       	echo '</li>
       <li><ul class="shop-block-list">';
       } ?>
   
       <li id="post-<?php the_ID(); ?>" <?php post_class("clearfix"); ?>>
   
       	<div class="shop-block-img-wrapper">
   
       		<?php if( has_post_thumbnail() ) { ?>
       			<a>" rel="bookmark" title="<?php the_title_attribute(); ?>">
       				<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'image-style3' ); ?>
       				<?php echo '<img src="' . $src[0] . '" alt="" />'; ?>
       			</a>
   
       		<?php } else { ?>
       			<a>" rel="bookmark" title="<?php the_title_attribute(); ?>">
       				<?php echo '<img src="' . get_template_directory_uri() . '/images/image2.png" alt="" />'; ?>
       			</a>
       		<?php } ?>
   
       	</div>
   
       	<h4><a>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
   
       </li>
       <?php if ( $current_num % 3 == 0 ) {
       	echo '';
       } elseif ( $current_num == $wp_query->post_count ) {
       	echo '';
       } else {
       	//echo '';
       } ?>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4390972)
 * >  the code below that is set to pick up different cathegories. How can I change
   > it to only search for category id=81 for example?
 * you did not post any relevant code where this might happen;
 * consider to post the full code of the template – possibly use the _pastebin_;
   see [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391169)
 * Thank you!
 * I try to be more clear! I use a theme that has severeal sections on the frontpage.
   One section is called: Two Column Mini Slideshow Loop.
 * I want this to repeat twice, but if I only copy this code: [http://pastebin.com/CndxTCW7](http://pastebin.com/CndxTCW7),
   I will get the same categorys repeating. So I thought if I can write the php-
   code in a way that it only get one category I can work this out. The other way,
   to get it to work in the admin of the theme, is to advanced for me. I am still
   a beginner.
 * /Karin
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391254)
 * The categories used in your code snippet are contained in `$data['home2cols_slide_col1_cat']`
   and `$data['home2cols_slide_col2_cat']`. The values appear to come from your 
   theme admin settings, this is where you should be setting the categories desired,
   it should not be that advanced a skill.
 * To answer your question, replacing every occurrence of those variables with the
   string (or integer as appropriate) value of the desired category ID will result
   in a slideshow in each loop limited to the specified category ID.
 * For example, for category 81 to be used in the first loop. replace every occurrence
   of `$data['home2cols_slide_col1_cat']` with `'81'` or `81` as appropriate, in
   lines 13 and 14:
 *     ```
       $home2cols_slide_col1_cat = '&cat=' . '81';
       $thecat = get_category(81);
       ```
   
 *  Thread Starter [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391274)
 * Thank you for your response. I can add categories for the two columns that are
   in the theme admin from start. But I don´t know how to add kolumn three and four
   to the theme admin. Is this easy? I thought this was complicated?
 * Do you know I guide to learn this?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391288)
 * It is not complicated, but getting the CSS right can be a challenge sometimes.
   It is probably not possible from the admin screens, otherwise the method would
   have been obvious. To get 4 columns you can simply repeat the same code, but 
   change the categories used as I indicated previously. Of course in this case 
   you cannot use the admin settings for categories. You will also need to change
   the class names in the HTML elements.
 * This will yield 4 different lists of content, but the appearance on the page 
   will probably not be to your liking. Changing the appearance involves possibly
   altering the CSS of the existing columns. And certainly adding new CSS for the
   new columns. Depending on how the existing content CSS works, this can be easy
   or difficult.
 * If you have trouble adapting the existing CSS, a different approach would be 
   to find an example 4 column layout you like on the Web. There are many CSS examples
   for all sorts of layouts. Alter your HTML output and CSS file to match the example.
   This is more complicated, but possible if you proceed carefully and keep backups
   of the original files in case things do not go well.
 *  Thread Starter [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391289)
 * Thank you very much for you guide! I managed to copy the code and work with the
   css. There is only one problem left that I cant solve.
 * This is the url to the page:[http://www.poppet.se/](http://www.poppet.se/)
    at
   the end of the page you see the columns. When doing what you suggested I get 
   the right header above but the images are from the sama category. Did I miss 
   something?
 * /Karin
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391298)
 * Apparently 🙂
 * Each column has a separate call to `query_posts()`. The category ID parameter
   for the last column needs to be changed, it is apparently the same as the previous
   column.
 * Similarly, the `<h3>` line just before also needs to be edited to reflect the
   different category and corresponding link.
 *  Thread Starter [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391299)
 * I managed to change the <h3> line. But were do I change the category in this 
   code /<?php query_posts( “post_type=post” . $home2cols_slide_col2_cat . $home2cols_slide_col2_limit);?
   >/
 * I tried to use the code you gave me before like this: /<?php query_posts( “post_type
   =post” . $home2cols_slide_col2_cat= ‘&cat=’ . ’81’;
    $thecat = get_category(81);?
   >/
 * … but that doesn´t work.. Do I miss something?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391306)
 * Yeah, there’s a syntax issue there. It’s my fault, I changed strategies on you
   between posts, apologies. This should work for you:
    `<?php query_posts( 'post_type
   =post&cat=81' . $home2cols_slide_col2_limit ); ?>`
 * I sort of changed strategies yet again by running together the fixed string portions,
   simplifying so it’s more clear what’s really happening.
 * This makes anything in the code you copied that is related to `$home2cols_slide_col2_cat`
   irrelevant. Other than being slightly less efficient, it doesn’t hurt anything.
   Once this is all resolved and working correctly, if you’re feeling adventurous,
   try commenting out the irrelevant portions. If you can do that without breaking
   anything, it would be safe to delete the commented text. Still, keep backups 
   just in case 🙂
 *  Thread Starter [KarinMA](https://wordpress.org/support/users/karinma/)
 * (@karinma)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391308)
 * Thank you very much for all the help! Now everything works perfectly! I guess
   commenting out irrelevant code is a great way to learn!
 * /Karin
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391314)
 * You are most welcome.
 * My thought exactly for a learning opportunity. Have fun!

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

The topic ‘Changing the loop’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 11 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/changing-the-loop/#post-4391314)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
