WordPress.org

Ready to get started?Download WordPress

Forums

Seperating Posts in Page templates using Categories (4 posts)

  1. mpfrink
    Member
    Posted 4 years ago #

    http://mitchfrink.com/

    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.

  2. Devin Price
    Member
    Posted 4 years ago #

    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:

    <?php
    
    //The Query
    query_posts('posts_per_page=5&cat=8');
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
     ..
    endwhile; else:
     ..
    endif;
    
    //Reset Query
    wp_reset_query();
    
    ?>

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

    <?php
     $portfolio_items = get_pages('child_of=48&numberposts=4&sort_column=post_date&sort_order=desc');
     foreach($portfolio_items as $post) :
        setup_postdata($post);
    ?>
    
    <p>Whatever you want to display</p>
    
    <?php endforeach; ?>
  3. mpfrink
    Member
    Posted 4 years ago #

    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:
    http://mitchfrink.com/photography

    <?php
    /*
    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 } ?>            
    
                    </div>   	
    
    				<?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>
                        <div class="fix"></div>
    
                        <?php the_excerpt(); ?>
    
                    </div>               
    
    				<div class="fix"></div>
    			</div>
    			<!--/box-->
    
                <?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>		
    
    		<div class="fix"></div>
    	</div>
    	<!--/columns -->
    
    <?php get_footer(); ?>
  4. Devin Price
    Member
    Posted 4 years ago #

    You should post this in the Woo Themes forum.

    Where is says:

    query_posts("cat=".$GLOBALS['ex_pf']."&paged=$paged");

    Change it to:

    query_posts("cat=8&paged=$paged");

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.