1
votes

All,

Would appreciate any help! Just took over a site and am having an issues with the category pages. They're currently showing all blog posts rather than just those belonging to their category. I'm pretty sure the issue can be found in the category.php file. It looks like the previous developer set up the FAQ page by submitting them as blog posts, see below:

<?php foreach((get_the_category()) as $category) { 
        $cat_id =  $category->cat_ID; 
    }

    if ($cat_id == 38 or $cat_id == 49 or $cat_id == 47 or $cat_id == 48){
        get_template_part( 'content','faq');
    }
    else{
        get_template_part( 'content','blog');
    }
    ?>

Any suggestions would be welcome, thanks!

1

1 Answers

0
votes

Once you create a category.php file, WordPress will automatically recognize it as the category template, so you only have to use The Loop as you normally would.

There are some functions that you can use like:

<p>Category: <?php single_cat_title(); ?></p>

or

<?php if (is_category('Category A')) : ?>
<p>This is the text to describe category A</p>
<?php elseif (is_category('Category B')) : ?>
<p>This is the text to describe category B</p>
<?php else : ?>
<p>This is some generic text to describe all other category pages, 
I could be left blank</p>
<?php endif; ?>

You can get more info in the WordPress Codex. https://codex.wordpress.org/Category_Templates