返回介绍

posts_nav_link()

发布于 2017-09-11 09:56:04 字数 4178 浏览 1048 评论 0 收藏 0

posts_nav_link( string $sep = '',  string $prelabel = '',  string $nxtlabel = '' )

Displays the post pages link navigation for previous and next pages.


description


参数

$sep

(string) (Optional) Separator for posts navigation links.

Default value: ''

$prelabel

(string) (Optional) Label for previous pages.

Default value: ''

$nxtlabel

(string) (Optional) Label for next pages.

Default value: ''


源代码

File: wp-includes/link-template.php

function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
	$args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
	echo get_posts_nav_link($args);
}

更新日志

Versiondescription
0.71Introduced.

相关函数

Uses

  • wp-includes/link-template.php: get_posts_nav_link()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Codex

    Using Images

    
    <?php posts_nav_link( ' ', '<img src="' . esc_attr( get_bloginfo( 'stylesheet_directory' ) . '/images/prev.jpg . ')'" />', '<img src="' . esc_attr( get_bloginfo( 'stylesheet_directory' ) . '/images/next.jpg . ')'" />' ); ?>
    
  2. Default Usage

    By default, the posts_nav_link() look like this:

    « Previous Page — Next Page »

    
    <?php posts_nav_link(); ?>
    

    In Centered DIV

    Displays previous and next page links (“previous page · next page”) centered on the page.

    
    <div style="text-align:center;">
    	<?php posts_nav_link( ' · ', 'previous page', 'next page' ); ?>
    </div>
    

    Kubrick Theme Format

    The Kubrick theme format for posts navigation, could be formatted this way. However, using posts_nav_link() in this way will result in unintended behavior, such as double stacked next and previous links that link to the incorrect sections.

    The Kubrick Theme actually uses next_posts_link() and previous_posts_link().

    This is poor code and should not be used:

    
    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link( '', '', '&laquo; Previous Entries' ); ?></div>
    <div class="alignright"><?php posts_nav_link( '', 'Next Entries &raquo;', '' ); ?></div>
    </div>
    

    This is better code:

    
    <div class="navigation">
    <div class="alignleft"><?php previous_posts_link( '&laquo; Previous Entries' ); ?></div>
    <div class="alignright"><?php next_posts_link( 'Next Entries &raquo;', '' ); ?></div>
    </div>
    

    You can change the text in each of the links and in the text in between the links.

    You can go back to the previous page or you can go forward to the next page.

    
    <p><?php posts_nav_link( ' or ', 'You can go back to the previous page', 'you can go forward to the next page' ); ?>.</p>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文