how to Single.php page add BACK button to parent category for WordPress
Way 1:
------------------------------------
<?php
$cats=get_the_category();
foreach($cats as $cat){
if($cat->category_parent == 0 && $cat->term_id != 1){
echo '<h2 class="link"><a href="'.get_category_link($cat->term_id ).'">Return</a></h2>';
}
break;
}
?>
Way 2:
------------------------------------
<a href="<?php $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID); ?>">Return</a>
------------------------------------
<?php
$cats=get_the_category();
foreach($cats as $cat){
if($cat->category_parent == 0 && $cat->term_id != 1){
echo '<h2 class="link"><a href="'.get_category_link($cat->term_id ).'">Return</a></h2>';
}
break;
}
?>
Way 2:
------------------------------------
<a href="<?php $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID); ?>">Return</a>
Comments
Post a Comment