![](/img/trans.png)
[英]how can i use “+” and “,” for category_name in WP_Query?
[英]Wordpress loop using wp_query category_name => category+textstring
我有一个wp_query获取与当前页面标题相同的类别的所有帖子。
我陷入困境的地方是修改wp_query category_name => $post->post_name
加上文本字符串。
例如,如果页面被称为“ Long Day”,则会显示所有类别为“ long-day”的帖子。 我需要在一个循环中引入这些帖子,在另一个循环中添加post_name以及文本字符串(例如,long-day-today)。
这是我到目前为止所拥有的...
<?php
global
$post; $args = array(
'category_name' => $post->post_name
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="entry"><?php the_content(); ?></div>
<?php echo $cat ?>
<?php endwhile; else: ?>
<p>Sorry, there are no posts to display</p>
<?php endif; ?>
[编辑]
我现在有点傻了,玩了一段时间之后,我想到了这个
global
$post;
$exclude = "hello";
$args = array(
'category_name' => "{$post->post_name} . $exclude"
);
似乎可以解决问题,如果有更好的方法可以实现这一点,我仍然很想听听...
谢谢
global
$post;
$exclude = "hello";
$args = array(
'category_name' => "{$post->post_name} . $exclude"
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.