wordpress – displaying category and subject posts

I have single post pages, that displays the page subheading based on the category name or subject name. I am having issues display category titles as well as subject name. Essential what I am trying to achieve is if the post is not selected as subject them display the page heading as a category.

Below is a snippet of my code, I have working to display subject names, however, I am struggling to display category names, if posts do not have subject names.

<?php

$classes = array();

$terms = get_the_terms( get_the_ID(), ‘subject’ );

$categories = get_the_terms( get_the_ID(), ‘category’);

if(sizeof($terms) > 1 ) {
$classes[] = “reset”;
}
else
{
foreach($terms as $term)
{
$classes[] = $term->slug;
}
}
?>
<div class=”columns small-12 “>
<div class=”single-title <?php echo implode($classes, ‘ ‘);
?>”>
<h2>
<?php if(count($subjects) == 0)
{
$categories = get_the_terms( get_the_ID(), ‘category’ );
}
?>
</h2>
<hr/>
</div>
</div>

Read more here:: wordpress – displaying category and subject posts

Leave a Reply

Your email address will not be published. Required fields are marked *