Products
GG网络技术分享 2025-03-18 16:12 4
我想通过TAG标签调用某个栏目相同标签的文章。
$post_num = 8; global $post;
$tmp_post = $post;
$tags = ''; $i = 0;
if ( get_the_tags( $post->ID ) ) {
foreach ( get_the_tags( $post->ID ) as $tag ) $tags .= $tag->name . ',';
$tags = strtr(rtrim($tags, ','), ' ', '-');
$myposts = get_posts('numberposts='.$post_num.'&tag='.$tags.'&exclude='.$post->ID);
foreach($myposts as $post) {
setup_postdata($post);
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
$post = $tmp_post; setup_postdata($post);
以上代码为通过当前文章tag调用全站相同tga标签的文章列表。
我想要实现只调用某个分类下的同tag文章,怎么实现(分类ID为'4')
试试这个,传入category参数
$myposts = get_posts('numberposts='.$post_num.'&category=4&tag='.$tags.'&exclude='.$post->ID);
###
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!Demand feedback