I am struggling to get my category.php to fetch and display the correct posts by category as per the slug in the url. So for example www.example.com/category/news should display all the posts tagged with the category 'news' - but currently it displays all posts which is odd...
How can I get the category ID as I understand thats the value to pass into the loop rather than the actual name to then just display the posts that match the category id from from url?
This captures the category name - but I need the id
<?php $page_object = get_queried_object(); ?>
<h1><?php echo $page_object->cat_name; ?></h1>
Which I can then pass into:
<?php query_posts('cat=ID HERE'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
So looking to capture the ID of /category/name and pass it into the code
Any ideas?
WORKED IT OUT MYSELF - solution below:
<?php $page_object = get_queried_object(); ?>
<?php $categoryID= $page_object->cat_ID; ?>
<?php query_posts("cat=$categoryID"); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
WORKED IT OUT MYSELF - solution below:
<?php $page_object = get_queried_object(); ?>
<?php $categoryID= $page_object->cat_ID; ?>
<?php query_posts("cat=$categoryID"); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>