1 Replies - 3516 Views - Last Post: 23 May 2010 - 09:09 AM

#1 Guest_taylor*


Query One Category For Blog Homepage in Wordpress

Posted 19 May 2010 - 12:20 PM

I adjusted my site in the "Reading" section to show a static page as the homepage and the posts show up on page "Blog."

I want only posts from the category "blog" to show up on the blog page and in the blog sidebar. I have different sections of my site and I want posts from specific categories to show up in specific sections. All of the sections work properly except the main blog, which shows all the different categories.

I added the query_posts code to my index.php file which is the template for the Blog page. The code works fine on my "journals" pages, only showing posts from that category. It's only not working on the blog homepage. http://www.peainthepodcast.com/blog

Journal Section (works correctly):

Here is my index.php code:
<?php get_header(); ?>

<div id="blog">

<?php include (TEMPLATEPATH . '/sidebar.php'); ?>

	<?php query_posts('cat=115'); if (have_posts()) : while (have_posts()) : the_post(); ?>

<div id="blog_post">

<div class="post" id="post-<?php the_ID(); ?>">
	 <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
	<p>posted by <?php the_author_posts_link(); ?></a> on <div class="post_date"><?php the_date('','',''); ?></div></p>

		<?php the_content(__('(more...)')); ?>
		<?php edit_post_link(__('Edit This')); ?>
		<div class="post_footer">
		Categories: <?php the_category(',') ?> 
        Tags: <?php the_tags(__(' '), ', ', '  '); ?> 
		<?php comments_popup_link(__('Comments (Leave a Comment)'), __('Comments (1)'), __('Comments (%)')); ?>

<?php comments_template(); // Get wp-comments.php template ?>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

<?php posts_nav_link('  ', __('&laquo; Newer Posts'), __('Older Posts &raquo;')); ?>

<div class="content_bottom"></div>
<?php get_footer(); ?>

Is This A Good Question/Topic? 0

Replies To: Query One Category For Blog Homepage in Wordpress

#2 calebjonasson   User is offline

  • $bert = new DragonUnicorn(); $bert->rawr();
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: Query One Category For Blog Homepage in Wordpress

Posted 23 May 2010 - 09:09 AM

If I am reading the question properly, You need an if statement for the query posts function. Something like this will do the trick for you except you will have to replace is_home with the page you want it on.

if (is_home()){

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1