List posts in a certain category
-
I really need some help with this guys!
I’m looking for a plugin or a way to list all posts in a certain category using my archive.php file.
When clicking a category in the menu, it will list all posts in that category.
The only plugins I’ve found are those that you can use in a post or a page, but I want to be able to list all post directly in my archive.php file.
Hopefully someone understands what I’m looking for, or is able to help me out. It’s really important for my site.
-
If you don’t have a category.php then the Template Hierarchy will use archive.php to display your category posts.
But if that doesn’t work for you:
<?php $cat_id = get_cat_ID('My Category'); $args=array( 'cat' => $cat_id, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo 'List of Posts in My Category'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php the_content(); endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
But, right now all my posts show up like on my main page, with an excerpt, but all I want is to be able to create an list with all posts in that category, so that it’s easier to find the post I’m looking for.
Something like this:
- This is a post
- Another post
- Yet another post
And so on, until it has looped through all posts.
Perhaps theres a way to modify the code I have in my archive.php?
Or maybe I should create a file called category.php and add the code you gave me.
I’ll give it a try, but will probably need more guidance.
Now I have managed to get it all in a list, but still one problem. The list only shows 10 posts, then it puts a wp_pagenavi below where you can choose to show ten more.
I want to show all my posts in one page.
Here’s my code:
<?php get_header(); ?> <div id="content"> <div id="column"> <?php if (have_posts()) : ?> <div class="post"> <h2> Arkivet för kategorin ‘<?php single_cat_title(); ?>’ </h2> <ul> <?php while (have_posts()) : the_post(); ?> <div class="entry"> <li> <a href="" <?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?> </a> </li> </div> <?php endwhile; ?> </ul> <!-- Plugin Navigation --> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> <!-- End --> </div> <?php else : ?> <div class="post"> <h1>No posts were found.</h1> <p>Sorry! the page you are looking for does not exist.</p> <h3>Blog Search</h3> <?php include(TEMPLATEPATH."/searchform.php"); ?> </div> <?php endif; ?> </div> <?php get_sidebar(); ?> <div class="clear"></div> </div> <?php get_footer(); ?>
Got it working now using this plugin: http://wordpress.org/extend/plugins/custom-post-limits/
Thank for all the help!
- The topic ‘List posts in a certain category’ is closed to new replies.