• I would like to set up a page template that allows me to build the page based on the posts of a certain category. I know I can used the cat=# setup to do this, but I want something that automates this a bit.

    My idea is to have the page load, look at the title of the page and if there is a category with that same name, show the posts of that category.

    An example:
    Page is created called “Dogs”
    I would want the Dogs page to look for a category named dogs and if it is there show the posts. If not, then some other default text.

    The challenge is that I don’t want to have to create a new page template for each category. I want the page to get the title, and if category=’title’, show posts.

    I hope I am describing this in a way that makes sense.
    Any ideas?

Viewing 2 replies - 16 through 17 (of 17 total)
  • funkboybilly::

    Hai thanks funkboybilly…
    Actually i am trying to get some code..from past 3 days …
    while I got it here by ur comment…and I tried to use this for my one…

    it works perfectly thank u very much…

    Thanks
    anil.
    [email protected]

    I added on to funkboybilly code so that it looks similar to the category page whihc includes title link, date, tags, etc.
    In the page template paste it under the
    <h1><?php the_title(); ?></h1><br /> that is already there.

    Here is the code:

    <!-- CODE TO SHOW POSTS -->
    <?php $catname = wp_title('', false); ?>
    <?php query_posts("category_name=$catname&showposts=10"); ?>
    <?php $posts = get_posts("category_name=$catname&numberposts=3&offset=0");
    foreach ($posts as $post) : start_wp(); ?>
    <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    
    				<div class="dateleft">
    					<p><span class="time"><?php the_time('F j, Y'); ?></span> <?php _e("by", 'studiopress'); ?> <?php the_author_posts_link(); ?> &nbsp;<?php edit_post_link(__('(Edit)', 'studiopress'), '', ''); ?> <br /> <?php _e("Filed under", 'studiopress'); ?> <?php the_category(', ') ?></p>
    				</div>
    
    				<div class="dateright">
    					<p><span class="icomment"><a rel="nofollow" href="<?php the_permalink(); ?>#comments"><?php comments_number(__('Leave a Comment', 'studiopress'), __('1 Comment', 'studiopress'), __('% Comments', 'studiopress')); ?></a></span></p>
    				</div>
    
    			<div class="clear"></div>
    <?php the_excerpt(__('Read more', 'studiopress'));?>
    			<div class="clear"></div>
    
    			<div class="postmeta2">
    <p><span class="tags">Tags: <?php the_tags('') ?></span></p>
    			</div>
    <?php endforeach; ?>
    
    <!-- END-->

    Then remove the line of code below this:
    <?php the_excerpt(__('Read more', 'studiopress'));?> that was previously there so you dont have you content displaying twice.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Creating Page Based on Category’ is closed to new replies.