使用wp_query category_name=>类别+文本字符串的wordpress循环


Wordpress loop using wp_query category_name => category+textstring

我有一个wp_query,即获取与当前页面标题相同的类别中的所有帖子。

我陷入困境的地方是修改wp_query category_name => $post->post_name加上一个文本字符串。

例如,如果页面要称为"长日",

则将显示所有类别为"长日"的帖子。我需要在一个循环中引入这些帖子,并在另一个循环中post_name加上文本刺痛,例如今天长日。

这就是我到目前为止所拥有的...

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