2012-03-23 18 views
0

こんにちは私はカテゴリ5から最初の投稿を取得しようとすると2つの異なるクラスを作る。しかし、私のすべての投稿は、クラス "定期的"を取得する、私は最初の投稿(最初の投稿のみ)クラス "特集"し、残りのクラスの "定期的な"は何が間違って把握できないようにします。ハーフ! :)私は、コードの最初の行を削除する場合 ああところで、コードは動作しますが、それはすべてのカテゴリからすべての記事を取得します:/カテゴリのワードプレスの最初の投稿

<?php query_posts('cat=5'); 
    while (have_posts()) : the_post(); ?> 

    <?php if (is_paged()) : $postclass = ('regular'); ?> 
    <?php else : ?> 
    <?php $postclass = ($post == $posts[0]) ? 'featured' : 'regular'; ?> 
    <?php echo $postclass; ?> 
    <?php endif; ?> 
    <?php endwhile ?> 

答えて

0

はなぜあなたのループの外で「特集」に$postclass設定してみてください、とありませんそれが表示されたら、それを「通常」に設定しますか?どのようにブール値を使用することについて、

<?php 
query_posts('cat=5'); 
$postclass = 'featured'; 
while (have_posts()) : the_post(); 

    if (is_paged()) : 
     $postclass = 'regular'; 
    else : 
     echo $postclass; 
     $postclass = 'regular'; 
    endif; 
endwhile 
?> 

それともそれはあなたに意味をなさない場合:

ロジックを変更することなく、あなたのコードに小さな変更を作りますか?

<?php 
query_posts('cat=5'); 
$first = true; 
while (have_posts()) : the_post(); 

    if (is_paged()) : 
     $postclass = 'regular'; 
    else : 
     $postclass = $first ? 'featured' : 'regular'; 
     echo $postclass; 
     $first = false; 
    endif; 
endwhile 
?> 
関連する問題