下面是帖子模板中的Wordpress代码。php for the wp\\u link\\u pages()函数-此函数为内容拆分为多个页面的帖子或页面生成页面导航。
function wp_link_pages($args = \'\') {
$defaults = array(
\'before\' => \'<p>\' . __(\'Pages:\'), \'after\' => \'</p>\',
\'link_before\' => \'\', \'link_after\' => \'\',
\'next_or_number\' => \'number\', \'nextpagelink\' => __(\'Next page\'),
\'previouspagelink\' => __(\'Previous page\'), \'pagelink\' => \'%\',
\'echo\' => 1
);
$r = wp_parse_args( $args, $defaults );
$r = apply_filters( \'wp_link_pages_args\', $r );
extract( $r, EXTR_SKIP );
global $page, $numpages, $multipage, $more, $pagenow;
$output = \'\';
if ( $multipage ) {
if ( \'number\' == $next_or_number ) {
$output .= $before;
for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
$j = str_replace(\'%\',$i,$pagelink);
$output .= \' \';
if ( ($i != $page) || ((!$more) && ($page==1)) ) {
$output .= _wp_link_page($i);
}
$output .= $link_before . $j . $link_after;
if ( ($i != $page) || ((!$more) && ($page==1)) )
$output .= \'</a>\';
}
$output .= $after;
} else {
if ( $more ) {
$output .= $before;
$i = $page - 1;
if ( $i && $more ) {
$output .= _wp_link_page($i);
$output .= $link_before. $previouspagelink . $link_after . \'</a>\';
}
$i = $page + 1;
if ( $i <= $numpages && $more ) {
$output .= _wp_link_page($i);
$output .= $link_before. $nextpagelink . $link_after . \'</a>\';
}
$output .= $after;
}
}
}
if ( $echo )
echo $output;
return $output;
}
这里的问题是,生成的标记,即使是通过参数,也不能用于Twitter引导页面导航类,因为标记应该是这样的:
<div class="pagination">
<ul>
<li class="disabled"><span>Pages:</span></li>
<li class="active"><span><a href="#current-page">1</a></span></li>
<li><span><a href="#next-page">2</a></span></li>
</ul>
</div>
然后我尝试使用以下参数:
\'before\' => \'<div class="pagination"><ul><li class="disabled"><span>\' . __( \'Pages:\', \'mytextdomain\' ) . \'</span></li>\',
\'after\' => \'</ul></div>\',
\'link_before\' => \'<li><span>\',
\'link_after\' => \'</span></li>\',
但结果是:
<div class="pagination">
<ul>
<li class="disabled"><span>Pages:</span></li>
<li><span>1</span></li>
<a href="#somelink">
<li><span>2</span></li>
</a>
</ul>
</div>
正如您所看到的
<li>
页码的元素错误地嵌套到
<a>
元素。通过查看函数,我可以了解原因。但是,我不确定应该如何继续修复标记。如何筛选或编辑此函数以更正标记?我应该重写一个全新的吗?