How to call a certain category for a wordpress page

Asked

Viewed 2,736 times

0

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

For example : I have a page in the menu about MUSICAS and I would like you to call 1 category example : ROCK.

I tried with the code below but appeared all categories not only the one I mentioned above ( https://wordpress.org/support/topic/display-the-posts-of-one-category-in-a-page-solved )

     <?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(); ?>

1 answer

0


From what I’ve noticed you’re using a Page as a template just the $wp_query global(default) of the file will actually bring up the Page Template query and not the query of a category even if you change in the query_posts() method,for such a thing to happen 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: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Browser other questions tagged

You are not signed in. Login or sign up in order to post.