WordPress.org

Ready to get started?Download WordPress

Forums

Display posts from a single category (2 posts)

  1. chriseddie
    Member
    Posted 1 year ago #

    Right now I have a piece of code on my homepage that is pulling in the most recent posts from a set of categories. However, I only want it to pull in the posts from category #15. Can someone please help me tweak this code to do that?

    <?php $allCats = get_categories();
    
    						$blogCats = array();
    						$blogcat = get_cat_ID(get_option('15'));
    
    						foreach ($allCats as $category) {
    							if (in_subcat($blogcat, $category->cat_ID)) $blogCats[] = $category->cat_ID;
    						}
    
    						$args = array('category__not_in' => $blogCats,
    									  'showposts' => get_option('portfolio_number'));
    
    						$i = 1;
    						query_posts($args);
    						if (have_posts()) : while (have_posts()) : the_post(); ?>
    							<?php include(TEMPLATEPATH . '/includes/gallery.php'); ?>
    						<?php $i++; endwhile; endif; wp_reset_query(); ?>
  2. Pete
    Member
    Posted 1 year ago #

    If you do a Google search there is a heap of answers to this

    <?php
    query_posts('posts_per_page=5&cat=15');
    while(have_posts()) : the_post();
    ?>
    <ul>
    <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    
    <ul><li><?php the_content(); ?></li>
    </ul>
    </li>
    </ul>
    <?php endwhile; ?>

    or...

    <?php $recent = new WP_Query(); ?>
    <?php $recent->query('cat=15&showposts=5'); ?>
    <?php while($recent->have_posts()) : $recent->the_post(); ?>
    <ul>
        <li>
                <a href="<?php the_permalink(); ?>">
                <?php the_title(); ?>
                </a>
           </li>
    </ul>
    <?php endwhile; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic