Support » Themes and Templates » Seperating Posts in Page templates using Categories


    I recently changed my site to use a portfolio theme with two portfolio pages. Web Design displaying websites I’ve created and the second is Photography. Displaying the Photos I’ve taken and edited. Each page has a separate page template and currently they are both loading all posts both web and photography. I need to add code in each page template to only load posts in that specific category page. (posts in the photography category only load in the photography page, etc.)

    I just don’t know the correct coding to add?

    if it helps the category ids are as follows:

    Photography = ID 8
    Web Design = ID 6

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can create a page template for the landing page and then use the query_posts to display them. For photography (category 8), you would have something like:

    //The Query
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    endwhile; else:
    //Reset Query

    And just in case you wanted to have your portfolio items as pages rather than posts:

     $portfolio_items = get_pages('child_of=48&numberposts=4&sort_column=post_date&sort_order=desc');
     foreach($portfolio_items as $post) :
    <p>Whatever you want to display</p>
    <?php endforeach; ?>

    Thanks downstairs dev,

    I realized I should have added the code for the page template, as I’m not sure where to add the code you gave me and if I need to remove something that’s there already.

    Here is the code for page-photoportfolio.php or this page here:

    Template Name: Photography
    <?php get_header(); ?>
    	<div id="columns" class="no-bg">
                <h2>MY PHOTOGRAPHY</h2>
    			<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=".$GLOBALS['ex_pf']."&paged=$paged"); if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); $count++; ?>
    			<div class="box portfolio">
    				<?php if ( get_post_meta($post->ID,'image', true) ) { ?> <!-- DISPLAYS THE IMAGE URL SPECIFIED IN THE CUSTOM FIELD -->
    				<div class="pic fl">
    					<?php $resize = get_option('woo_portfolio_resize'); if ($resize) { // Check if we should use the image resizer ?>
                        <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&h=<?php if ( get_option('woo_portfolio_image_height') <> "" ) { echo get_option('woo_portfolio_image_height'); } else { ?>180<?php } ?>&w=<?php if ( get_option('woo_portfolio_image_width') <> "" ) { echo get_option('woo_portfolio_image_width'); } else { ?>515<?php } ?>&zc=1&q=95" alt="<?php the_title(); ?>" /></a>       
                         <?php } else { ?>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a>
                        <?php } ?>            
    				<?php } ?>										
    				<div class="item-text">
                        <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                        <div class="portfolio-meta">                   
    					<?php if ( get_post_meta($post->ID, "url", $single = true) <> "" ) { ?>
                            <span class="website"><a href="<?php echo get_post_meta($post->ID, "url", $single = true); ?>" title="Visit The Website">Website</a></span>
    					<?php } ?>
                            <span class="details"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Details</a></span>
    					<?php if ( get_post_meta($post->ID, "preview", $single = true) <> "" ) { ?>
    						<span class="larger"><a href="<?php echo get_post_meta($post->ID, "preview", $single = true); ?>" title="Preview - <?php the_title(); ?>" rel="lightbox">Large Image</a></span>
    					<?php } ?>
                        <div class="fix"></div>
                        <?php the_excerpt(); ?>
    				<div class="fix"></div>
                <?php endwhile; ?>
                <?php endif; ?>
                <div class="navigation">
                    <div class="fl"><?php next_posts_link('&laquo; Previous Entries') ?></div>
                    <div class="fr"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    		<div class="fix"></div>
    	<!--/columns -->
    <?php get_footer(); ?>

    You should post this in the Woo Themes forum.

    Where is says:


    Change it to:


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Seperating Posts in Page templates using Categories’ is closed to new replies.