我有一个wp_query获取一个类别中的所有帖子,其标题与当前页面的标题相同。
我遇到的问题是修改wp_query category_name => $post->post_name
加上文本字符串。
例如,如果要将页面称为“漫长的一天”,则会显示所有类别为“长日”的帖子。我需要在一个循环中引入这些帖子,在另一个循环中引入post_name加上文本sting,例如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"
);
这似乎可以解决问题,如果有更好的方法可以实现这一点,我仍然有兴趣听到...
由于
答案 0 :(得分:0)
global
$post;
$exclude = "hello";
$args = array(
'category_name' => "{$post->post_name} . $exclude"
);