请教:wordpress怎么调用子分类标题和子分类的文章
用了以下方式调用,输出的是文章所有分类的文章。怎么调用指定分类的文章?另外如果这个子分类a包括子分类b、c的话,子分类a会把bc的文章都调用出来,就重复了。
谢谢大佬解答。
[*] $cat,
[*]'parent' => $cat,
[*]'hide_empty' => 0
[*]));
[*]$c = get_category($cat);
[*]if(empty($cats)){
[*]?>
[*]
[*]
[*]
[*]" href="">
[*]
[*]">more >>
[*] | 标签:
[*]
[*]
[*]
[*]暂无文章
[*]
[*]
[*]
[*]
[*]
[*]
[*] $the_cat->cat_ID,
[*]'numberposts' => 10,
[*]));
[*]if(!empty($posts)){
[*]echo '
[*]
[*]name.'" href="'.get_category_link($the_cat).'">'.$the_cat->name.'
[*]';
[*]foreach($posts as $post){
[*]echo '[*]'.mysql2date('Y-m-d', $post->post_date).'
[*]post_title.'" href="'.get_permalink($post->ID).'">'.$post->post_title.'';
[*]}
[*]echo '
[*]';
[*]}
[*]}
[*]}
[*]?>
[*]复制代码 [*]
[*] 1, // 分类ID
[*] 'posts_per_page' => 10, // 显示篇数
[*] );
[*] query_posts($args);
[*] if(have_posts()) : while (have_posts()) : the_post();
[*]?>
[*] [*]
[*] "> //标题
[*]
[*] post_content)), 0, 170,"……"); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
[*] } ?>
[*]
[*]
[*]
[*]复制代码
或者用这个方式调用,怎么能把子分类的名称调用出来?现在调用出来的只有文章的名称。 晕。。。官网一查就有的答案
$category_detail=get_the_category('4');//$post->ID
foreach($category_detail as $cd){
echo $cd->cat_name;
}
XiaoFaye 发表于 2019-4-10 07:59
晕。。。官网一查就有的答案
$category_detail=get_the_category('4');//$post->ID
我试一下哈
XiaoFaye 发表于 2019-4-10 07:59
晕。。。官网一查就有的答案
$category_detail=get_the_category('4');//$post->ID
这段话放在什么位置呢?
mylawer 发表于 2019-4-10 08:54
这段话放在什么位置呢?
在the_post(); 后面
$id = get_the_ID();
$category_detail = get_the_category($id);
foreach($category_detail as $cd){
echo $cd->cat_name;
}
XiaoFaye 发表于 2019-4-10 09:14
在the_post(); 后面
$id = get_the_ID();
这个是每个标题前面都会有分类。
我想的样式是这样:
大分类
子分类1
文章1
文章2
子分类2
文章1
文章2
这样~
XiaoFaye 发表于 2019-4-10 09:14
在the_post(); 后面
$id = get_the_ID();
发现一个笨方法,就是把这段代码根据子分类多少就复制多少个代码,这样调用也能实现,哈。
页:
[1]