我正在尝试使用is_singular函数的条件逻辑帮助检查和设置内容。但这是行不通的。我已经为单发布循环创建了三个文件,single.php,single-post1.php,single-post2.php。 single.php带有默认的post url参数。 single-post1.php附带了/?L=2
的额外提示,例如
,因此也适用于single-post2.php。但是现在当我想通过检查is_singular函数加载single-post1.php文件时,它不起作用,仅在其他情况下起作用。有没有更好的主意来应用这种情况。将非常感谢您的帮助。使用的代码如下...
function bootstrap_wp_link_pages($wp_links){
global $post;
// Generate current page base url without pagination.
$post_base = trailingslashit( get_site_url(null, $post->post_name) );
$wp_links = trim(str_replace(array('<p>Pages: ', '</p>'), '', $wp_links));
// Get out of here ASAP if there is no paging.
if ( empty($wp_links) )
return '';
// Split on spaces
$splits = explode(' ', $wp_links );
$links = array();
$current_page = 1;
// Since links are now split up such that <a and href=".+" are seperate...
// loop over split array and correct links.
foreach( $splits as $key => $split ){
if( is_numeric($split) ) {
$links[] = $split;
$current_page = $split;
} else if ( strpos($split, 'href') === false ) {
$links[] = $split . ' ' . $splits[$key + 1];
}
}
$num_pages = count($links);
// Output pagination
$output = '';
$output .= '<ul class="pagination">';
if ( $current_page == $num_pages )
{
$output .= '<li class="disabled"><a> </a>';
}
elseif(is_singular('post1'))
{
$output .= '<li><a href="' . $post_base . ($current_page + 1) . '/?L=2">';
$output .= 'Next Page</a></li>';
}
elseif(is_singular('post2') )
{
$output .= '<li><a href="' . $post_base . ($current_page + 1) . '/?L=3">';
$output .= 'Next Page</a></li>';
} // end the li. No reason to duplicated this in both conditionals.
else
{
$output .= '<li><a href="' . $post_base . ($current_page + 1) . '/?L=4">';
$output .= 'Next Page</a></li>';
} // end the li. No reason to duplicated this in both conditionals.
$output .= '</ul>';
return $output;
}
add_filter('wp_link_pages', 'bootstrap_wp_link_pages');