外贸营销

wordpress wp_link_pages同时支持数字与上下页
2019.09.06 外贸营销

在wordpress里有个函数wp_link_pages是给文章内容分页的,可是默认的只支持要么显示数字,要么显示下一页按钮,而没有同时显示的,肿么办,将以下代码加入主题的functions.php里即可:

add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');function wp_link_pages_args_prevnext_add($args){ global $page, $numpages, $more, $pagenow;if (!$args['next_or_number'] == 'next_and_number')  return $args; # exit early$args['next_or_number'] = 'number'; # keep numbering for the main part if (!$more) return $args; # exit earlyif($page-1) # there is a previous page $args['before'] .= _wp_link_page($page-1) . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>' ;if ($page<$numpages) # there is a next page $args['after'] = _wp_link_page($page+1) . $args['link_before'] . '' . $args['nextpagelink'] . $args['link_after'] . '</a>' . $args['after'] ;return $args;}

然后,调用:

<?php wp_link_pages( array(<?php wp_link_pages( array( 'before' => '<div class="page-links">', 'after'  => '</div>',            'next_or_number' => 'next_and_number',            'link_before'      => '<span>',    'link_after'       => '</span>',            'nextpagelink'     => 'NEXT',    'previouspagelink' => 'PREV', ) ); ?>
上一篇下一篇
标签

有问
必答