時間:2023-06-07 02:09:02 | 來源:網(wǎng)站運營
時間:2023-06-07 02:09:02 來源:網(wǎng)站運營
WordPress主題自己如何做分頁:分頁可讓您的用戶通過多頁內(nèi)容來回瀏覽。<!--nextpage-->
<?php if ( have_posts() ) : ?> <!-- Add the pagination functions here. --> <!-- Start of the main loop. --> <?php while ( have_posts() ) : the_post(); ?> <!-- the rest of your theme's main loop --> <?php endwhile; ?> <!-- End of the main loop --> <!-- Add the pagination functions here. --> <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php else : ?> <?php _e('Sorry, no posts matched your criteria.'); ?> <?php endif; ?>
注意:在使用分頁循環(huán)的模板文件外部使用任何這些分頁函數(shù)時,必須調(diào)用全局變量$wp_query。
function your_themes_pagination(){ global $wp_query; echo paginate_links();}
WordPress具有許多功能,用于顯示您循環(huán)中其他頁面的鏈接。 這些功能中的一些僅在非常具體的上下文中使用。 您將在單個頁面上使用不同的功能,然后在歸檔頁面上。 以下部分介紹歸檔模板分頁功能。 之后的部分封面單后分頁。posts_nav_link();
next_posts_link(); previous_posts_link();
如果您需要將分頁鏈接傳遞給PHP變量,則可以使用get_next_posts_link()和get_previous_posts_link()。$next_posts = get_next_posts_link(); $prev_posts = get_previous_posts_link();
the_posts_pagination();
對于4.1之前的WordPressecho paginate_links();
previous_post_link();next_post_link();
<!--nextpage-->
如果您在內(nèi)容中使用該標簽,則需要確保將wp_link_pages函數(shù)放在循環(huán)中的single.php模板中。<?php if ( have_posts() ) : ?> <!-- Start of the main loop. --> <?php while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php wp_link_pages(); ?> <?php endwhile; ?> <?php endif; ?>
關(guān)鍵詞:主題
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。