Title: categor in page
Last modified: August 20, 2016

---

# categor in page

 *  [josef.dalal](https://wordpress.org/support/users/josefdalal/)
 * (@josefdalal)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/)
 * hi,
    i build a page in a new template that i make and insert second loop for 
   category. the page is displaying the normal page content and include query_posts();
   that displaying the_title & the_excerpt . so far so god, but i want it to go 
   further and with the (‘cat=X’) following by the query post i wanted to make the
   X dynamic!
 * i try to make a custom filed key that will contain the the number of the category
   id but it went bad!
 * does anyone know a better way to include a unique category for different pages
   with a dynamic option? or reference to how to or something?
    thanks in advance
   josef
 *     ```
       <?php
       // The Query
       query_posts('cat=5');
       ?>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/#post-2129982)
 * can you paste the full code of the tempalte into a [http://pastebin.com/](http://pastebin.com/)
   and post the link to it here?
 * there should be no problem to use a custom field per page to retrieve a category
   id;
 * somehow partly related example (which uses the category name): [http://codex.wordpress.org/Pages#A_Page_of_Posts](http://codex.wordpress.org/Pages#A_Page_of_Posts)
 *  Thread Starter [josef.dalal](https://wordpress.org/support/users/josefdalal/)
 * (@josefdalal)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/#post-2130010)
 * hi alchymyth.
    first thanks for the link to codex.
 * i put here the relevant code for did (the basic loops)
    i also register the custom
   field on the function.php and call it “catnum” my idea was to some how use the
   catnum as input cat id and manually insert it from the page.
 *  `<?php echo get_post_meta($post->ID, 'catnum', true); ?>`
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * thanks josef
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/#post-2130015)
 * getting the custom field value and creating a query should happen here before
   the start of the second loop:
 *     ```
       <!--start the category section-->
       <?php
        if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * example:
 *     ```
       <!--start the category section-->
       <?php
       $cat = get_post_meta($post->ID, 'catnum', true);
       query_posts('posts_per_page=5&cat=' . $cat);
        if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * then add `wp_reset_query();` after the `endif;` of the second loop.
 * ref: all possible parameters for `query_posts()` (they are the same as for `WP_Query()`):
   
   [http://codex.wordpress.org/Class_Reference/WP_Query#Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Parameters)
 *  Thread Starter [josef.dalal](https://wordpress.org/support/users/josefdalal/)
 * (@josefdalal)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/#post-2130027)
 * WOW
    thanks allot, now it soundes simple… thanks – alchymyth

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

The topic ‘categor in page’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [josef.dalal](https://wordpress.org/support/users/josefdalal/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/categor-in-page/#post-2130027)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
