How to call certain category for a wordpress page

0

I am creating a theme for wordpress but I am not able to call certain category on a page (which is in the menu).

For example: I have a page in the MUSIC menu and I would like it to call 1 example category: ROCK.

I tried the code below but it appeared all categories not just the one I mentioned above ( link )

     <?php
      /* Template name: solo */
     ?>

    <?php get_header(); ?>

    <div id="primary" class="content-area">
         <main id="main" class="site-main" role="main">

    <?Php 
    query_posts ('cat = 15 '); 

    while (have_posts ()): the_post (); 
    the_content (); 
    endwhile; 
    ?>

         </main>
    </div>

   <?php get_sidebar(); ?>
    
asked by anonymous 14.01.2015 / 23:37

1 answer

0

From what I noticed you are using a Page as template, the $ global wp_query (default) of the file will actually bring up the Page Template query and not the query for a category even though you change it in the query_posts () method, so that such thing happened you would have to use a taxonomy.php or category.php. To solve your problem you need to create a new WP_Query;

$customQuery = new WP_Query('cat=15');
if($customQuery->have_posts()) :
   while($customQuery->have_posts()): $customQuery->the_post();
       the_content();
   endwhile;
endif;

For more information and examples: link

    
15.01.2015 / 00:00