Title: Sections
Last modified: August 19, 2016

---

# Sections

 *  [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/)
 * In WordPress, I am trying to have content from only a certain category be shown
   in a certain section of the website.
 * I am using this code in a certain section of my website. If i want content from
   a specified category to appear in this area, what do I have to do?
 *     ```
       <?php if ($aOptions['column2-id'] != '') { query_posts('p=' . $aOptions['column2-id']); } ?>
       <?php while (have_posts()) : the_post(); ?>
       <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
       <?php the_content(''); ?>
       <?php endwhile; ?>
       ```
   

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

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002636)
 * Hi
 * Your code appears to be pulling in a post or posts ID, not a category.
 * The simple syntax for what you want is
    `query_posts('cat=4');`
 * to use the contents of PHP variables like this
 *     ```
       $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC';
       query_posts($query)
       ```
   
 * If you haven’t seen the query_posts codex page it is here
    [http://codex.wordpress.org/Template_Tags/query_posts](http://codex.wordpress.org/Template_Tags/query_posts)
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002714)
 * That script that i posted above came with the template. But how can I get is 
   to pull from a category instead of using Post ID?
 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002729)
 * I just gave you the code to do that (above)
 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002730)
 * Categories have their own category ID codes – that is what is being specified
   in the query_posts code I posted
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002872)
 * Sorry. I am very noob with PHP. Can you please tell me exactly what to put in
   the place of
 *     ```
       <?php if ($aOptions['column2-id'] != '') { query_posts('p=' . $aOptions['column2-id']); } ?>
       <?php while (have_posts()) : the_post(); ?>
       <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
       <?php the_content(''); ?>
       <?php endwhile; ?>
       ```
   
 * Because the code that you posted seems like it needs to be in some brackets or
   something. It didn’t work. :S
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002943)
 * Just a lil more help please. I am not very good with PHP. 🙁
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002980)
 * Please help…
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002981)
 *     ```
       <?php if ($aOptions['column2-id'] != '') { query_posts('cat=4&p=' . $aOptions['column2-id']); } ?>
       <?php while (have_posts()) : the_post(); ?>
       <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
       <?php the_content(''); ?>
       <?php endwhile; ?>
       ```
   
 * See this part i just added…
 * `cat=4`
 * Adjust the 4 to the ID of your chosen category…
 * You can tell which ID your category has by viewing it on your website, the link
   in the browser should be something like…
 * [http://www.yoursite.com/index.php?cat=1](http://www.yoursite.com/index.php?cat=1)
   
   or [http://www.yoursite.com/index.php?cat=2](http://www.yoursite.com/index.php?cat=2)
   or [http://www.yoursite.com/index.php?cat=3](http://www.yoursite.com/index.php?cat=3)
 * and so on…
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002995)
 * Hi,
 * I entered in the following code for the sections at [http://www.mountoliveadventist.org](http://www.mountoliveadventist.org)
 *     ```
       <?php if ($aOptions['column2-id'] != '') { query_posts('cat=3&p=' . $aOptions['column2-id']); } ?>
       <?php while (have_posts()) : the_post(); ?>
       <h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h3>
       <?php the_content(''); ?>
       <?php endwhile; ?>
       ```
   
 * However, nothing is showing. I even got the plugin that reviews the ID’s for 
   each category. And I know I chose the right category because if you go to [http://mountoliveadventist.org/?cat=3](http://mountoliveadventist.org/?cat=3)
   it will show the content.
 * Please help. Thanks.
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002996)
 * For testing sake, does it work if you change this line..
 * `<?php if ($aOptions['column2-id'] != '') { query_posts('cat=3&p=' . $aOptions['
   column2-id']); } ?>`
 * To..
 * `<?php query_posts('cat=3');?>`
 *  Thread Starter [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * (@bestcssdesigns)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002998)
 * Yes. Thanks so much!

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

The topic ‘Sections’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 3 participants
 * Last reply from: [bestcssdesigns](https://wordpress.org/support/users/bestcssdesigns/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/sections-1/#post-1002998)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
