导读:建站技术建站技术如果需要在分类列表页面,显示当前分类文章中添加的所有标签,方便读者阅读自己喜欢的内容,下面的代码可以帮你实现这个功能。 首先,在主题functions.php模建站技术论坛网站平台搭建。
如果需要在分类列表页面,显示当前分类文章中添加的所有标签,方便读者阅读自己喜欢的内容,下面的代码可以帮你实现这个功能。
首先,在主题functions.php模板文件中添加以下函数:
function get_category_tags($args) {
global $wpdb;
$tags = $wpdb->get_results
("
SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name
FROM
$wpdb->posts as p1
LEFT JOIN $wpdb->term_relationships as r1 ON p1.ID = r1.object_ID
LEFT JOIN $wpdb->term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms1 ON t1.term_id = terms1.term_id,
$wpdb->posts as p2
LEFT JOIN $wpdb->term_relationships织梦cms模板 as r2 ON p2.ID = r2.object_ID
LEFT JOIN $wpdb->term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms2 ON t2.term_id = terms2.term_id
WHERE
t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
AND p1.ID = p2.ID
ORDER by tag_name
");
$count = 0;
if($tags) {
foreach ($tags as $tag) {
$mytag[$count] = get_term_by('id', $tag->tag_id, 'post_tag');
$count++;
}
} else {
关键词标签: 建站 文章 标签
声明: 本文由我的SEOUC技术文章主页发布于:2023-07-23 ,文章获取WordPress当前分类文章所有标签,建站技术主要讲述标签,文章,建站网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_35338.html