0
votes

I am very newbie into wordpress development so i had face a issue for displaying some post for specific category...

Like, I am adding(posting) some images into database for post_picture category...

Now at front end i have a page name Picture Mania where i just want to display only those image which i added into post_picture category...

For this purpose first i installed the php-exec plugin , and now I am trying to retrieve my desire category images on that page by this code

<?php query_posts('post_picture =post_picture&showposts=5');
while (have_posts()) : the_post();
  // do whatever you want
?>
<?php get_template_part( 'content', get_post_format() ); ?>
                <?php cup_post_nav(); ?>
                <?php comments_template(); ?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>

It working fine, but displaying all category images, so conclusion I am not getting my desire output...

Answer will be much appreciated....and thanks for help in advance

3

3 Answers

3
votes

You can pass category id (cat=3) such as

<?php query_posts('cat=3&showposts=5');
while (have_posts()) : the_post();
  // do whatever you want
?>
<?php get_template_part( 'content', get_post_format() ); ?>
                <?php cup_post_nav(); ?>
                <?php comments_template(); ?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>

Or you can use category name in arary as well:

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

query_post Reference: http://codex.wordpress.org/Function_Reference/query_posts

Although WP_Query is recommended approach instead of query_posts

1
votes

for showing posts of specific category, you could add cat=YOUR_CATEGORY_ID in query_posts() like:

query_posts('post_picture=post_picture&showposts=5&cat=$your_Category_Id');

as in query_posts() example

1
votes

try this:

<?php query_posts('cat=your-post_picture-category-id&showposts=5');

while (have_posts()) : the_post();
// do whatever you want
?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php cup_post_nav(); ?>
<?php comments_template(); ?>
<b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"> 
<?php the_title(); ?></a>