• oloranya

    (@oloranya)


    I’m just starting to learn how to use the new Post Format feature and I haven’t been able to find help for what I’m trying to do via google.

    I’ve got the post formats working for single post pages, using this code:

    <?php
    			/* Run the loop to output the posts.
    			 * If you want to overload this in a child theme then include a file
    			 * called loop-index.php and that will be used instead.
    			 */
    	get_template_part( 'format', get_post_format() );
    	?>

    With template files of format-link.php, format-image.php etc. to define what the single posts look like. The entire loop is contained in the format templates.

    What I want to do is combine this method of displaying post types, with the ability to run a loop that only displays posts from certain categories.

    So, ideally, I’ll have the main page with two loops on it, one showing posts from the ‘news’ category, and one showing posts from the ‘portfolio’ category. Then, I’ll have a Journal page which shows posts from the ‘blog’ category.

    This is the code I’m using to display posts from a specific category:

    <?php
      		    $category_id = get_cat_id('journal');
       		    $q = 'cat=' . $category_id;
         		query_posts($q);
         		if (have_posts()) : while (have_posts()) : the_post(); ?>
    
         			<div class="news_post">
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
    					<?php the_excerpt(); ?>
    
    				</div>
    
     		<?php endwhile; else: ?>
        	<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
         	<?php endif; ?>

    I’ve tried just sticking the get_template_part in between the php that tells it to call posts only from the given category and the endif, but it didn’t work.

    Can anyone tell me how I can combine these two bits of code to make them work?

The topic ‘Custom Post Types & Category Specific Loops’ is closed to new replies.