[wp-hackers] Re: Page with only articles from category x.

Alex Polite mylists at polite.se
Thu Sep 13 17:20:22 GMT 2007


OK peoples.

I tried out page2cat which would be perfect for me but it didn't seem to work.

Then I started experimenting with page templates under K2. I know some
of you feel that K2-questions don't belong here but I feel that this
is  stuff that might as well have been done in standard WP.

I use a custom key to define the category instead of hard coding it.


=======================================
<?php /*
        Template Name: Page With Category
        Set a custom key named "category" on your page and let the
value be the category_name of the category you wish to display
*/ ?>

<?php get_header(); ?>

<div class="content">
    <div id="primary">
     <div id="dynamic-content"> <?php include (TEMPLATEPATH .
'/rollingarchive.php'); ?> </div> <!-- #dynamic-content -->
      <div id="current-content" class="hfeed">
       <?php

        $category_name = get_post_meta($post->ID, "category", true);

        query_posts("category_name=$category_name");
        global $more;
        $more = 0;
        include (TEMPLATEPATH . '/theloop.php');
        comments_template();     ?>



      </div> <!-- #current-content -->
     </div> <!-- #primary -->
    <?php get_sidebar(); ?>
</div> <!-- .content -->

<?php get_footer(); ?>



=======================================


-- 
http://polite.se


More information about the wp-hackers mailing list