我有一个功能,允许用户在分页和下一个/上一个链接之间进行选择。事实上,我在这个网站上得到了这个功能。我今天测试了一下,它突然不起作用了。我想不出这次突然中断的原因。
如果我选择我想要的选项,切换主题,保存,然后切换回来,代码似乎会起作用!完全不知道发生了什么事。
在函数中。php:
// Pagination
function my_theme_navigation()
{
global $shortname;
if( get_option( $shortname . \'_next_prev_or_paginate\' ) == \'Next\' ) :
// the block for next-prev navigation
echo \'<div class="left">\';
next_posts_link(\'Older\');
echo \'</div>\';
echo \'<div class="right">\';
previous_posts_link (\'Newer\');
echo \'</div>\';
else :
// the block for pagination
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links(
array(
\'base\' => str_replace( $big, \'%#%\', get_pagenum_link( $big ) ),
\'format\' => \'?paged=%#%\',
\'end_size\' => 1,
\'mid_size\' => 2,
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $wp_query->max_num_pages
)
);
endif;
}
在“我的选项”面板中:
array( "name" => "Paginate or next/previous links?",
"desc" => "Choose your option",
"id" => $shortname."_next_prev_or_paginate",
"type" => "select",
"options" => array("Next/Previous Links", "Pagination"),
"std" => "Next"),
在索引中。php:
<?php my_theme_navigation(); ?>
最合适的回答,由SO网友:Chip Bennett 整理而成
这是您的问题:
"options" => array("Next/Previous Links", "Pagination"),
"std" => "Next"
您的有效选项与默认选项不匹配。
更改此项:
"std" => "Next"
。。。对此:
"std" => "Next/Previous Links"
然后,在函数调用中,更改以下内容:
if( get_option( $shortname . \'_next_prev_or_paginate\' ) == \'Next\' )
。。。对此:
if( get_option( $shortname . \'_next_prev_or_paginate\' ) == \'Next/Previous Links\' )