Thread Starter
c-m
(@c-m)
I don’t want to specify the category though. I want only to show the posts of the category that’s been clicked on.
At the moment I’ve got
<ul>
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li>';
echo '<div class="post-details-wrapper">';
echo '<h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
echo '<p>'. $category->description . '</p>';
echo '</div>';
echo '</li>';
}
?>
</ul>
But that just lists all categories, not list the posts within the selected category.
I want only to show the posts of the category that’s been clicked on.
that would get automatically get done via the category archive template, possibly category.php, of your theme.
what theme are you using?
Thread Starter
c-m
(@c-m)
I’m building one from scratch, and it’s category.php I’m working.
I’ve got most things down, I just can’t seem to understand the loop for categories.
I’m also trying to do a slight variation on this, where I display the sub categories of a main category, rather than the posts.
I think that is where I’m getting confused.
a general loop structure of a category.php for your desired html output would be:
<?php if( have_posts() ) : ?>
<ul>
<?hp while( have_posts() ) : ?>
<li>
<?php the_post_thumbnail(); ?>
<div class="post-details-wrapper">
<h3><?php the_title(); ></h3>
<?php the_ecerpt(); ?>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Thread Starter
c-m
(@c-m)
Thanks very much. Just the same as a normal loop. I should have clocked that.