I might wish to design the class web page for them. on this web page, we’ve got to point out the final class of every publish beside every publish title.
So I wish to show the final class from every publish, on the classes pages.
the vital level for me is that I wish to take away a selected class with all kids from the end result.
I put the beneath code on loop.php
<?php echo get_last_category()?>
and the perform is:
perform get_last_category($class="")
{
$current_post_id = get_the_ID();
$args = array(
'orderby' => 'term_order',
'exclude_tree' => [2621],
'hide_empty' => 0,
'fields' => 'all'
);
$phrases = wp_get_post_categories($current_post_id,$args);
if ($phrases==null){echo 1;} // for take a look at
$cat = array();
foreach ($phrases as $time period) {
$cat[] = '<a category="' . $class . '" href="' .
esc_attr(esc_url(get_category_link($term->term_id))) . '">' . $term->identify .
'</a>';
}
return finish($cat);
}
the issue is that if I’ve 50 posts on one of many classes web page. it simply reveals me the class’s identify for the primary publish.
for different posts, it returns null!
**OUTPUT**:
Put up tile 1[category name]
Put up title 2[1]
Put up title 3[1]
Put up title 4[1]
Put up title 5[1]
Put up title 6[1]
.
.
.
I realy dont know why wp_get_post_categories()
return null after first time!