Reputation: 4984
List post categories that link to a page showing those posts.
Hi all
I have posts with different categories.
I have a blog page that lists the posts like this.
<?php
$blog_args = array(
'post_type' => 'post',
'order_by' => 'date',
'order' => 'ASC'
);
$blog_loop = new WP_Query($blog_args);
if($blog_loop->have_posts()):
while($blog_loop->have_posts()):
$blog_loop->the_post();
?>
<div class="row">
<div class="col-sm-3 img-responsive">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive"));
}
?>
</div>
<div class="col-sm-9">
<h3><?php echo the_title(); ?></h3>
<p><?php echo the_content(); ?></p>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
I would like to have a list of the different categories on the blog page. If I click the category I would like to show the post with that catogory.
I can list the categories like so.
<ul>
<?php
wp_list_categories('title_li=>');
?>
</ul>
If I click the link it takes me to an empty page with the name of the category in the URL.
How can I list the categories and link to show the post with that category.
Upvotes: 0
Views: 101
Reputation: 3648
add a file in your theme called category.php
then add the loop code into it.
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title();?>
<?php the_content();?>
<?php endwhile; wp_reset_postdata(); endif; ?>
<?php get_footer(); ?>
Upvotes: 1