experience

经验

zw-1988.com

home > 经验 > wordpress 上一页下一页

2017.7.12 wordpress 上一页下一页

zwnet

放到function里

<?php function single_page_nav_link() {
	?>
<div class="post_nav_link">
    <?php
		$categories = get_the_category();
		$categoryIDS = array();
		foreach ( $categories as $category ) {
			array_push( $categoryIDS, $category->term_id );
		}
		$categoryIDS = implode( ",", $categoryIDS );
		?>
        <div class="pre_post">
            <?php if (get_previous_post($categoryIDS)){previous_post_link('&#171 %link','%title',true);}else{ echo 'Prev Post: (NG)';}?>
        </div>
        <div class="next_post">
            <?php if (get_next_post($categoryIDS)) {next_post_link('%link','%title &#187',true);}else{ echo 'Next Post: (NG)';}?>
        </div>
</div>
?>

有一览的地方

function single_page_nav_link() {
	?>
<div class="post_nav_link">
    <?php
		$categories = get_the_category();
		$categoryIDS = array();
		foreach ( $categories as $category ) {
			array_push( $categoryIDS, $category->term_id );
		}
		$categoryIDS = implode( ",", $categoryIDS );
		?>
        <div class="pre_post">
            <?php if (get_previous_post($categoryIDS)){previous_post_link('&#171 %link','%title',true);}else{ echo 'Prev Post: (NG)';}?>
        </div>
        <div class="nav_post"><?php
                $category = get_the_category();
                echo '<a href="'.get_category_link($category[0]->cat_ID).'">一覧に戻る</a>';
            ?></div>
        <div class="next_post">
            <?php if (get_next_post($categoryIDS)) {next_post_link('%link','%title &#187',true);}else{ echo 'Next Post: (NG)';}?>
        </div>
</div>
	<?php
}

 

在页面内详情页面直接调用

  <?php single_page_nav_link();?>

在页面利用检索想要分页栏

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query->is_archive = true;
$wp_query->is_home = false;
$args = array(
	'post_type' => 'tsukuba_rooms',
    'paged' => $paged,
	'tax_query' => array(
		array(
			'taxonomy' => 'rooms_category',
			'field'    => 'id',
			'terms'    => 56,
		),
	),
);
$query_news = new WP_Query($args);
if($query_news->have_posts()):
while($query_news->have_posts()):
$query_news->the_post();
$key1 = get_post_meta( get_the_ID(), '_my_meta_value_key1', true );
$key2 = get_post_meta( get_the_ID(), '_my_meta_value_key2', true );
$key3 = get_post_meta( get_the_ID(), '_my_meta_value_key3', true );
?>
<section>

</section>
<?php
endwhile;
endif;?>
<?php  $GLOBALS['wp_query'] = $query_news;
       the_posts_pagination( array(
       'prev_text'          => __( 'Previous', '' ),
       'next_text'          => __( 'Next', '' ),
       'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( '', '' ) . ' </span>',
) );;?>

‘     $GLOBALS[‘wp_query’] = $query_news;   ’这个很重要

‘  $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

$wp_query->is_archive = true;

$wp_query->is_home = false; ’如果页面检索后 分页不好使 一直显示第一页内容 就加上这段话

«
相关文章
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