-1

URLスタイルが : の場合に各カテゴリのランダムな投稿を表示する方法 : http://www.whatever.com/category/all-english/poetry/、カテゴリリンクをクリックするたびに異なる投稿が表示されます

私はこれを試しました:

$cat=get_query_var( 'cat' );
query_posts('cat=$cat&orderby=rand');
if (have_posts()) : 
    if ( $is_top_single ) $GLOBALS['more'] = false; //important
    while (have_posts()) : the_post(); ?>

しかし、結果は正しくありません。すべてのカテゴリのランダムな投稿が表示されます!

4

1 に答える 1

1

query_posts の使い方を学ぶ必要があります。archive.phpまたはcategory.php次のように編集できます。

query_posts(array(
    'showposts' => 6,
    'orderby' => 'rand',
    'category_name' => 'News' //You can insert any category name
));
if (have_posts()) : while (have_posts()) : the_post();
于 2012-05-26T23:47:51.563 に答える