2024年06月05日 建站教程
功能介绍:wordpress文章内容页面做一个返回功能,判断当前文章是否存在栏目,存在栏目返回栏目页,不存在返回指定页面或首页。
具体代码如下:
<div class="back">
<span onclick="window.location.href='<?php
$category = get_the_category();
if($category[0]){
echo ''.get_category_link($category[0]->term_id ).''; //返回到当前文章的栏目页
}else if(empty ( $category )){
echo '/'; //不存在栏目,返回首页
}
?>'">返回</span><?php
foreach((get_the_category()) as $category)
{
echo $category->cat_name;
}
?>
</div>
本文链接:http://so.lmcjl.com/news/5979/