8

I have create a category by using Custom Post Type plugin, and now only the 5 most recent posts of the category are showing.
What I want is to show all posts for the category.
For examle, suppose I have movies category - I want all movies in that category.
What code should I use and where?
I don't know much about the wordpress, so I would appreciate a step by step process.

  • I have written an article How To List All Posts Of An Archive … with the basic code for this very task. In short: set the parameter 'nopaging' for your query to TRUE. – fuxia May 18 '11 at 10:33
  • Because I'm not a developer, I've tried and I'm now using "Content Views". You can use it to display category posts only. Great plugin! – user91566 Mar 31 '16 at 23:15
7
   <?php
    $args = array( 'category' => 7, 'post_type' =>  'post' ); 
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?>  
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_excerpt(); ?>  
    <?php endforeach; ?> 

just change the category id (number 7) and change the post_type that was in the plugin

to learn more about post_type, see link http://codex.wordpress.org/Custom_Post_Types

2

It is quite easy to do it with wordpress. You have to understand that post are normally display within a "loop", a small code that repeat itself. You have to use one to do that.

<?php 
 $catPost = get_posts(get_cat_ID("NameOfTheCategory")); //change this
   foreach ($catPost as $post) : setup_postdata($post); ?>
       <div>
             <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
             <p><?php the_content(); ?></p>
       </div>
<?php  endforeach;?>

You should change the output to what fit your needs

0

This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request:

<?php
$catPost = get_posts('cat=888&posts_per_page=-1000');
   foreach ($catPost as $post) : setup_postdata($post); ?>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_post_thumbnail('name of your thumbnail'); ?>
  </a>

<h4>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <?php the_title(); ?>
  </a>
</h4>
<hr/ style="clear:both;">
<?php  endforeach;?>
0

You can use this code for accessing all post of specific category. In your category.php page use the spinet of code

$current_category = get_queried_object(); ////getting current category
$args = array(
        'post_type' => 'our-services',// your post type,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'cat' => $current_category->cat_ID // current category ID
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
   while($the_query->have_posts()): $the_query->the_post();
    echo "<h2>".the_title()."</h2>";
    echo "<p>".the_content()."</p>";
endwhile;
endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy