wordpress - How to create a page and attach a category to your page template automatically? -


i've created custom page template pulls in post entries based on category. i'm using query post category name pull them (page , category same). wondering if there way make don't have create page template each category/page?

i seems easier me create category template in category.php, , let template hierarchy deal queries.

however, if there pressing need page, , page's slug same category's slug, custom query achieve asking for:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();      $cat_query = new wp_query( array ( 'category_name' => $post->post_name ) );      if ( $cat_query->have_posts() ) : while ( $cat_query->have_posts() ) : $cat_query->the_post();          // inside custom category loop,         // category posts' magic happen         the_title( '<h2>' , '</h2>' );         the_content();      endwhile; endif;  endwhile; endif;  ?> 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -