experience

经验

zw-1988.com

home > 经验 > 各种导航

2017.11.29 各种导航

zwnet

在查询the_posts_pagination函数时搜到下文,用于调用WordPress内置的类似pagenavi分页式导航功能 。

add_theme_support( ‘title-tag’ )

通过声明这个特性,主题就能知道自身并没有定义标题,wordpress 就可以安全的添加标题而无须担心会导致重复添加。

<?php
function theme_slug_setup() {
   add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'theme_slug_setup' );?>

the_archive_title() / get_the_archive_title()

wordpress 的归档种类有 N 多种,日期、分类、标签、文章形式等……

<?php the_archive_title( '<h1 class="page-title">', '</h1>' );?>

the_archive_description() / get_the_archive_description()

和上一个函数类似,这个函数会返回归档的相关描述。

<?php the_archive_description( '', '' );?>

 

PS: 此函数不会返回作者描述

the_post_navigation() / get_the_post_navigation()

返回当前文章的前/后导航。

<?php while ( have_posts() ) : the_post();
    get_template_part( 'content', get_post_format() );
    the_post_navigation();
endwhile; // end of the loop.?>

the_posts_navigation() / get_the_posts_navigation()

返回文章列表的前/后导航。

<?php if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        get_template_part( 'content', get_post_format() );
    endwhile;
    the_posts_navigation();
else :
    get_template_part( 'content', 'none' );
endif;?>

the_posts_pagination() / get_the_posts_pagination()

返回文章列表的分页式导航。

<?php
if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        get_template_part( 'content', get_post_format() );
    endwhile;
    the_posts_pagination();
else :
    get_template_part( 'content', 'none' );
endif;
?>

the_posts_pagination

文章导航

<?php the_posts_pagination( array(
	'prev_text'          => __( 'Previous page', 'twentyfifteen' ),
	'next_text'          => __( 'Next page', 'twentyfifteen' ),
	'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
) );?>

«
相关文章
wordpress (25)java script (9)tool (8)css (2)攻略 (1)第一次人体 (1)插件 (1)ECharts (1)food (1)雪糕 (1)动画 (1)book (1)标签云 (1)生活 (1)一言难尽的画稿 (1)
辽ICP备16002031号

Copyright © 2016 - 2020 1988-zw.com