我只是想知道是否可以在wordpress中的foreach
循環中使用pagination_links()
函數? 當我嘗試它沒有任何反應,我環顧四周,似乎這比我期待有點麻煩......在wordpress中爲每個循環添加分頁
<?php
$args = array('numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts($args);
foreach ($postslist as $post) : setup_postdata($post); ?>
<div class="events">
<div class="newslistingblock">
<div class="newslistingblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
</div>
<div class="newslistingblockthumbnail">
<?php echo get_the_post_thumbnail($post_id, 'news-thumb', $attr); ?> </div>
<div class="newslistingexcerpt">
<?php the_excerpt(); ?> </div>
</div>
</div>
<?php endforeach; ?>
林基本上找的基本分頁,以「下一個」,「上一頁」和數字。
任何幫助,這將是非常感謝。
編輯: 我已經決定更改代碼以使之適合wordpress的...
<?php
query_posts('posts_per_page=5');
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<!-- Do suff -->
<div class="events">
<div class="newslistingblock">
<div class="newslistingblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
</div>
<div class="newslistingblockthumbnail">
<?php echo get_the_post_thumbnail($post_id, 'news-thumb', $attr); ?> </div>
<div class="newslistingexcerpt">
<?php the_excerpt(); ?> </div>
</div>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('← Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries →') ?></div>
</div>
<?php endif; ?>
張貼代碼嘗試發佈一個完整的塊時!在您的發佈代碼中,我無法看到您關閉「foreach」的位置.. – Deepak
哪裏試圖迴應您的分頁(並結束您的前期,就此而言)? –
用'var_dump' /'print_r'查看$ post中的內容,並自己動手:) – Bokw