Products
GG网络技术分享 2025-03-18 16:12 0
style.css : CSS(样式表)文件
index.php : 主页模板
archive.php : Archive/Category模板
404.php : Not Found 错误页模板
comments.php : 留言/回复模板
footer.php : Footer模板
header.php : Header模板
sidebar.php : 侧栏模板
page.php : 内容页(Page)模板
single.php : 内容页(Post)模板
searchform.php : 搜索表单模板
search.php : 搜索结果模板
is_home() : 是否为主页
is_single() : 是否为内容页(Post)
is_page() : 是否为内容页(Page)
is_category() : 是否为Category/Archive页
is_tag() : 是否为Tag存档页
is_date() : 是否为指定日期存档页
is_year() : 是否为指定年份存档页
is_month() : 是否为指定月份存档页
is_day() : 是否为指定日存档页
is_time() : 是否为指定时间存档页
is_archive() : 是否为存档页
is_search() : 是否为搜索结果页
is_404() : 是否为 “HTTP 404: Not Found” 错误页
is_paged() : 主页/Category/Archive页是否以多页显示
bloginfo (’name’); //博客名称(Title)
bloginfo (’stylesheet_url’); //CSS文件路径
bloginfo (’pingback_url’); //PingBack Url
bloginfo (’template_url’); //模板文件路径
bloginfo (’version’); // WordPress版本
bloginfo (’atom_url’); // Atom Url
bloginfo (’rss2_url’); // RSS 2.o Url
bloginfo (’url’); //博客 Url
bloginfo (’html_type’); // 博客网页Html类型
bloginfo (’charset’); //博客网页编码
bloginfo (’description’); //博客描述
wp_title(); //特定内容页(Post/Page)的标题
_e(’Message’); //输出相应信息
wp_register(); //显示注册链接
wp_loginout(); //显示登录/注销链接
<!––next page––> : 将当前内容分页
<!––more––> : 将当前内容截断,以不在主页/目录页显示全部内容
timer_stop(1); //网页加载时间(秒)
echo get_num_queries(); //网页加载查询量
is_single() 判断是否是具体文章的页面
is_single(’17′) 判断是否是具体文章(id=17)的页面
is_single(’Beef Stew’) 判断是否是具体文章(标题判断)的页面
is_single(’beef-stew’) 判断是否是具体文章(slug判断)的页面
comments_open() 是否留言开启
pings_open() 是否开启ping
is_page() 是否是页面
is_page(’42′) 同single,id判断,即是否是id为42的页面
is_page(’About Me’) title判断
is_page(’about-me’) slug判断
is_category() 是否是分类
is_category(’6′) 同single,id判断,即是否是id为6的分类
is_category(’Cheeses’) title判断
is_category(’cheeses’) slug判断
in_category(’5′) 判断当前的文章是否属于分类5
is_author() 将所有的作者的页面显示出来
is_author(’1337′) 显示author number为1337的页面
is_author(’Elite Hacker’) 通过昵称来显示当前作者的页面
is_author(’elite-hacker’)
is_date()
is_year()
is_month()
is_day()
is_time()
is_archive() 判断当前是否是归档页面
is_search() 判断是否是搜索
is_404() 判断页面是否404
is_paged() 判断是否翻页,比如你当前的blog是http://domain.com显示http://domain.com?paged=2的时候,这个判断将返回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界面,例如: if (is_home() && !is_paged() )
is_attachment() //判断是否是附件
我们在做wordpress企业网站的时候,经常需要调用当前分类文章列表,在新闻分类调用新闻分类的文章列表,产品分类就调用产品分类的文章列表。
首先需要在主题函数functions.php中加入功能函数:
functionget_category_tags($args){global$wpdb;
$tags=$wpdb->get_results
("
SELECTDISTINCTterms2.term_idastag_id,terms2.nameastag_name
FROM
$wpdb->postsasp1
LEFTJOIN$wpdb->term_relationshipsasr1ONp1.ID=r1.object_ID
LEFTJOIN$wpdb->term_taxonomyast1ONr1.term_taxonomy_id=t1.term_taxonomy_id
LEFTJOIN$wpdb->termsasterms1ONt1.term_id=terms1.term_id,
$wpdb->postsasp2
LEFTJOIN$wpdb->term_relationshipsasr2ONp2.ID=r2.object_ID
LEFTJOIN$wpdb->term_taxonomyast2ONr2.term_taxonomy_id=t2.term_taxonomy_id
LEFTJOIN$wpdb->termsasterms2ONt2.term_id=terms2.term_id
WHERE
t1.taxonomy='category'ANDp1.post_status='publish'ANDterms1.term_idIN(".$args['categories'].")AND
t2.taxonomy='post_tag'ANDp2.post_status='publish'
ANDp1.ID=p2.ID
ORDERbytag_name
");
$count=0;
if($tags){
foreach($tagsas$tag){
$mytag[$count]=get_term_by('id',$tag->tag_id,'post_tag');
$count++;
}
}else{
$mytag=NULL;
}
return$mytag;
}
然后在分类文件中加入调用代码:
<?php$cat=single_cat_title('',false);
$args=array('categories'=>get_cat_ID($cat));
$tags=get_category_tags($args);
$content.="<ulclass='cat-tag'>";
if(!empty($tags)){
foreach($tagsas$tag){
$content.="<li><ahref=\\"".get_tag_link($tag->term_id)."\\">".$tag->name."</a></li>";
}
}
$content.="</ul>";
echo$content;
?>
在需要调用列表的地方插入就可以了,样式可以自己定义
.cat-tag{float:left;
width:100%;
}
.cat-taglia{
float:left;
margin:05px;
}
这样就可以在当前文章分类,调用分类的文章列表了。
Demand feedback