WordPress 页面常用组件部分有公共头部导航,wordpress网站面包屑导航,wordpress网站侧边栏,当前列表分类的栏目名_栏目id_栏目链接。
<?php echo category_description( $category_id ); ?> //当前分类描述
<?php echo category_description(); ?> //当前分类描述
<?echo trim(strip_tags(category_description())); ?> //当前分类描述 不带默认p标签
<?
$category_title= single_cat_title('', false );
$category_id = get_cat_ID($category_title);
$category_link = get_category_link( $category_id );
echo $category_title; //输出当前分类名
echo $category_id; //输出当前分类id
echo $category_link //输出当前分类链接
?>
当前分类顶级分类栏目的分类名_链接(例:当前行业新闻,获取父分类新闻中心栏目名)
<a href="<?php echo get_category_link(get_category_root_id($cat)); ?>"><?php echo get_cat_name(get_category_root_id($cat)); ?></a>
functions添加获取当前分类子分类列表代码
//分类的子分类
function getchild($cat) {
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) // 若当前分类有上级分类时,循环
{
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬
}
return $this_category->term_id; // 返回根分类的id号
}
当前列表栏目子分类在需要调用当前顶级分类栏目的子分类处添加如下代码
<?php
if(is_single()||is_category()) { //如果是文件页面或分类页
if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" ) {//如果有子分类
echo '<ul class="sidebar-list1">';
echo wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)). "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC");
echo '</ul>';
}else{
//如果没有获取顶级分类
}
}
?>
列表循环、wordpress列表页循环调用标签
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li class=" homebk1-item">
<a href="<?php the_permalink(); ?>"> //链接
<div class="homebk1-img">
<img src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" /> //缩略图(特色图片)
</div>
<h3><?php the_title();?></h3> //标题方法一
<h3><?php wp_trim_words( get_the_title(), 10 );?></h3> //标题方法二 可限制字数
<p><? the_excerpt(); ?></p> //简介方法一
<p><?php wp_trim_words( get_the_excerpt(), 20 );?></p> //简介方法二 可限制字数
</a>
<p><?php the_date_xml()?> </p>
</li>
<?php endwhile;?>
<?php endif; ?>