0

私は PHP と WordPress の世界に不慣れで、特定のタグを持つ投稿のみを表示するループの作成に問題があります。

ホームページでは、特定のタグを設定した記事のみを表示するループを作成するため、wordpress 用に次の PHP ループを実装しました。

   <div id="column2">
        <?php   
            query_posts( 'tag=sasha' );  
            if(have_posts()): 
                while (have_posts()): the_post(); 
        ?>  

        <?php endwhile; else: ?>  
        <?php endif; ?> 
   </div> <!-- end column2 -->

次のようにタグを設定した記事があります: sasha

問題は、動作せず、私の column2 div がまだ空のままであることです。なんで?手伝って頂けますか?

TNX

アンドレア

4

1 に答える 1

1

を使用する場合、次のように表示されますWP_QUERY

$args = array('tag' => 'sasha');
$the_query = new WP_Query( $args );

while ( $the_query->have_posts() ) :
        $the_query->the_post();
        echo '<div>' . get_the_title() . '</div>';
        the_content();
endwhile;

wp_reset_postdata();
于 2013-03-19T12:19:56.687 に答える