2012-06-21 55 views
1

我怎麼能得到一個post_class「第一」頁上的每一個職位?頁面上的每個第一篇文章的第一課wordpress

使用此代碼爲循環的第一個帖子管理了一個類「first_post」,但我也需要它在循環的第二頁,第三頁等。

function.php

function firstpost_class($class) { 
    global $post, $posts; 
    if (is_home() && !is_paged() && ($post == $posts[0])) $class[] = 'firstpost'; 
    return $class; 
} 
add_filter('post_class', 'firstpost_class'); 

感謝您的幫助。谷歌無法幫助。

回答

0

我已經看到這種事情在循環本身上完成 - 評論澄清,如果你想做這個網站範圍內,或特別想鉤入post_class(然後再次,你可以編輯loop.php或一個內容LOOPTYPE.php並反覆使用它)。這裏有一個例子循環:

<?php 
$counter = 0; 
if (have_posts()) : while (have_posts()) : the_post(); 
$counter++; 
?> 

<div class="post <?php echo 'item-' . $counter; ?>"> 
    <?php the_title(); ?> 
    <?php the_content(); ?> 
</div> 

<?php endwhile; endif; ?> 

這將使你的項目1,項目-2,等等,等等

相關問題