Title: Help with PHP code
Last modified: August 19, 2016

---

# Help with PHP code

 *  [paulwallas](https://wordpress.org/support/users/paulwallas/)
 * (@paulwallas)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/)
 * Hi
 * I have wrote this piece of code so if the current page is category id 3 (my news
   category) then my news sub menu will appear.
 * It may be wrong but it works.
    if ($cat = array(3) ) { $cat = array(3);
 * What i want to do is apply the same rule for more categories. I need my portfolio,
   about and faq categories individuals menu’s to appear (id’s = 11,12,14) but i
   dont know how to add more to my code.
 * Can anyone help?

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316394)
 * Have a look at the [Category conditional tags](http://codex.wordpress.org/Conditional_Tags#A_Category_Page)
 * Eg:
 *     ```
       <?php if( is_category('3') ) get_sidebar('news');
       elseif( is_category('7') ) get_sidebar('services');
       else get_sidebar();?>
       ```
   
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316401)
 * For clarification, when you do this..
 *     ```
       if ($cat = array(3) ) {
       ```
   
 * You’re basically saying if $cat can equal to array(3) (which it can), then do..(
   whatever follows)..
 * That statement will always be true.. $cat will always be set to an array with
   the value of 3 ..
 * At least i believe that to be the case (based on my understanding).
 * Esmi’s suggestion above should set you in the right direction though.. 😉
 *  Thread Starter [paulwallas](https://wordpress.org/support/users/paulwallas/)
 * (@paulwallas)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316417)
 * thanks t31os_ it makes it a bit more clearer for me.
 * I have looked at esmi’s link and half works, however i am not displaying a side
   bar.
 * My site is set up with Home, About, News being categories and ‘education, experience,
   skills’ are all posts that display in the ‘about’ category.
 * Therefore if the page is currently the about us cat(id3) i want the posts within
   this category to show 🙂
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316421)
 * How is this different from using standard category pages?
 *  Thread Starter [paulwallas](https://wordpress.org/support/users/paulwallas/)
 * (@paulwallas)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316424)
 * Sorry i am not too sure what you mean?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316430)
 * Sorry – I was confused by your description of the situation. So is it that you
   want to show posts from 3 categories on the About category page? Or do you want
   to show different sub-menus on different category pages?
 *  Thread Starter [paulwallas](https://wordpress.org/support/users/paulwallas/)
 * (@paulwallas)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316517)
 * Hi
 * I want to show different sub menu’s on different category pages.
 * You can see the site [here](http://www.facetest.co.uk)
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316537)
 * To get the code I posted above to work, you need to have already created your
   custom sidebars – sidebar-news.php and sidebar-services.php in the example.

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

The topic ‘Help with PHP code’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [category](https://wordpress.org/support/topic-tag/category/)
 * [else](https://wordpress.org/support/topic-tag/else/)
 * [php if](https://wordpress.org/support/topic-tag/php-if/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/help-with-php-code/#post-1316537)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
