簡體   English   中英

使用wp_query category_name => category + textstring的Wordpress循環

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM