Short answer:
尝试
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
Long answer:
我看了一下
paginate_links()
源代码(
v3.5.1) 还有这条线(
#)
$link = str_replace(\'%_%\', 1 == $n ? \'\' : $format, $base);
这将为您提供空的第一页链接。
通过您的设置$base = "%_%"
和$format = "http://example.com/page/%#%/"
这就变成了:
$link = str_replace(\'%_%\', 1 == $n ? \'\' : "http://example.com/page/%#%/", "%_%");
我们有两个案例:
n=1: $link = str_replace(\'%_%\', \'\', "%_%");
n>1: $link = str_replace(\'%_%\', "http://example.com/page/%#%/", "%_%");
更换后:
n=1: $link = \'\';
n>1: $link = "http://example.com/page/%#%/";
下面是
paginate_links()
:
<ul class=\'page-numbers\'>
<li><a class="prev page-numbers" href="http://example.com/page/2/">« Previous</a></li>
<li><a class=\'page-numbers\' href=\'\'>1</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/2/\'>2</a></li>
<li><span class=\'page-numbers current\'>3</span></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/4/\'>4</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/5/\'>5</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/6/\'>6</a></li>
<li><a class="next page-numbers" href="http://example.com/page/4/">Next »</a></li>
</ul>
如果您使用(
#):
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
然后您会得到:
$link = str_replace(\'%_%\', 1 == $n ? \'\' : "?paged=%#%", "http://example.com/page/%#%");
因为不会更换
$link = "http://example.com/page/%#%";
在这两种情况下(n=1和n>1),您有一个非空的第一页链接,其输出为
paginate_links()
:
<ul class=\'page-numbers\'>
<li><a class="prev page-numbers" href="http://example.com/page/2/">« Previous</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/1/\'>1</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/2/\'>2</a></li>
<li><span class=\'page-numbers current\'>3</span></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/4/\'>4</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/5/\'>5</a></li>
<li><a class=\'page-numbers\' href=\'http://example.com/page/6/\'>6</a></li>
<li><a class="next page-numbers" href="http://example.com/page/4/">Next »</a></li>
</ul>
要有一个非空的首页链接
$format
可以是任意字符串,只要
$base
不包括字符串
"%_%"
, i、 e.这些应能正常工作:
\'format\' => \'?paged=%#%\',
\'format\' => \'page/%#%\',
\'format\' => \'asdfasdfasdfasdfasdf\',
如果不使用permalinks,那么(
#) 还将为您提供非空的首页链接,因为
$link = str_replace(\'%_%\', 1 == $n ? \'\' : "?paged=%#%", "http://example.com/?paged=%#%");
有替换件。