网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

wordpress文章调用问题

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);


###

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

标签:

提交需求或反馈

Demand feedback