[英]Wordpress loop using wp_query category_name => category+textstring
I have a wp_query getting all posts in a category with the same slug as the title as the current page. 我有一个wp_query获取与当前页面标题相同的类别的所有帖子。
Where i have become stuck is modifying wp_query category_name => $post->post_name
plus a text string. 我陷入困境的地方是修改
wp_query category_name => $post->post_name
加上文本字符串。
For example if page was to be called "Long Day" all posts with the category slug "long-day" will be shown. 例如,如果页面被称为“ Long Day”,则会显示所有类别为“ long-day”的帖子。 I need to bring in these posts in one loop and in another have post_name plus the text sting eg long-day-today.
我需要在一个循环中引入这些帖子,在另一个循环中添加post_name以及文本字符串(例如,long-day-today)。
This is what i have so far... 这是我到目前为止所拥有的...
<?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; ?>
[EDIT] [编辑]
I feel like a bit of a fool now, after a little playing i came up with this 我现在有点傻了,玩了一段时间之后,我想到了这个
global
$post;
$exclude = "hello";
$args = array(
'category_name' => "{$post->post_name} . $exclude"
);
Which seems to do the trick, if there is a better way of achieving this i would still be interested to hear... 似乎可以解决问题,如果有更好的方法可以实现这一点,我仍然很想听听...
Thanks 谢谢
global
$post;
$exclude = "hello";
$args = array(
'category_name' => "{$post->post_name} . $exclude"
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.