• Resolved qffkfrvu

    (@qffkfrvu)


    I have a page template that calls up some code to go in an area of the page. I’ve been hacking away for hours and i’m stuck like a pig in mud 🙁 I’d like to display posts from a particular category and cannot for the life of me figure out how to do it. Any help? 🙂

    The code below allows me to displays posts fine but i’d like to modify the query to get posts from a category, (i.e., news, updates, food, cats, etc) as currently it’s getting any new post.

    <h2>News</h2>
      	<?php query_posts(array('posts_per_page'=>1)); if (have_posts()) : while (have_posts()) : the_post(); ?>
      		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
      			<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
      			<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
      			<div class="entry">
      				<?php the_content(); ?>
      			</div>
      			<a class=readmore href="<?php the_permalink() ?>">> Read more</a>
      		</div>
      	<?php endwhile; ?>
      	<?php else : ?>
      		<h2>Not Found</h2>
      	<?php endif; ?>
      </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter qffkfrvu

    (@qffkfrvu)

    Thanks but i couldn’t get it working. I put in this code

    query_posts( array ( 'category_name' => 'category-slug', 'posts_per_page' => -1 ) );

    And it was pulling up all the posts in the category and displaying them in funny places on the page. I thought this code would only display one post from the page?

    Thread Starter qffkfrvu

    (@qffkfrvu)

    Ok, i got so far to display the number of posts ok but it’s still not displaying posts from the VIDEO category. Can anyone spot anything wrong?

    <?php query_posts(array ( 'video' => 'category-slug', 'posts_per_page' => 1 ) ); if (have_posts()) : while (have_posts()) : the_post(); ?>
      		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
      			<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
      			<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
      			<div class="entry">
      				<?php the_content(); ?>
      			</div>
      			<a class=readmore href="<?php the_permalink() ?>">> Read more</a>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to call up a post from a category (query_posts Categories)’ is closed to new replies.