这是一个可怕的、严重的、浪费时间的(两周)可怕的问题。
它可能是重写,我对自定义帖子的使用,但是在剥离了这么多(并减少了我的主题的一些功能)之后,我将我的问题简化为:
paginate_links()
正在发布这样的链接:
?s=cute&post_type=image&paged=2
当我将浏览器栏中的变量更改为 page=2 时(删除 'd')。
?s=cute&post_type=image&page=2
它工作正常。
所以我的问题简化为:如果我必须让该函数正确输出“页面”变量,那是如何完成的?
paged
并且paged
都被 WordPress 使用。paged
相反,如果这是更好的做法,我如何获得认可?
据我所知,这表明我的主题中存在一些更深层次的问题,但对于我的生活,我看不出我还有什么可能出错!
编辑:
这是我正在使用的代码:
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
$big = 999999999; // need an unlikely integer
$stuff_to_echo = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'type' => 'array'
) );
编辑 2 - 如果上述情况良好,这是问题可能发生的另一个可能区域。我将发布自定义帖子类型的创建和重写规则 -
//image custom post type
add_action( 'init', 'symbiostock_image_manager_register' );
function symbiostock_image_manager_register( )
{
//creating custom post type for image
$labels = array(
'name' => 'Symbiostock Images',
'singular_name' => 'Image',
'add_new' => 'New Image',
'add_new_item' => 'Add New Image',
'edit_item' => 'Edit Image',
'new_item' => 'New Image',
'all_items' => 'All Images',
'view_item' => 'View Image',
'search_items' => 'Search Images',
'not_found' => 'No image found',
'not_found_in_trash' => 'No images found in Trash',
'parent_item_colon' => '',
'menu_name' => 'RF Images'
);
$args = array(
'labels' => $labels,
'singular_label' => __( 'Image' ),
'description' => 'Image Listings',
'menu_position' => 100,
'menu_icon' => symbiostock_IMGDIR . '/symbiostock_icon2.png',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'exclude_from_search' => false,
'supports' => array(
'title',
'editor',
'thumbnail'
),
'rewrite' => array(
'slug' => 'image',
'with_front' => false
)
);
register_post_type( 'image', $args );
register_taxonomy( 'image-type', array(
'image'
), array(
'hierarchical' => true,
'label' => 'Image Categories',
'singular_label' => 'Image Type',
'rewrite' => true,
'exclude_from_search' =>false,
'public' => true,
'slug' => 'image-type'
) );
register_taxonomy( 'image-tags', array(
'image'
), array(
'hierarchical' => false,
'rewrite' => true,
'query_var' => true,
'singular_label' => 'Image Keyword',
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'slug' => 'image-tag',
'labels' => array(
'name' => _x( 'Image Keywords', 'taxonomy general name' ),
'singular_name' => _x( 'Keywords', 'taxonomy singular name' ),
'search_items' => __( 'Search Images' ),
'all_items' => __( 'All Image Keywords' ),
'edit_item' => __( 'Edit Image Keyword' ),
'update_item' => __( 'Update Image Keyword' ),
'add_new_item' => __( 'Add New Image Keyword' ),
'new_item_name' => __( 'New Keyword Name' ),
'menu_name' => __( 'Image Keywords' ),
),
'rewrite' => array(
'slug' => 'search-images', // This controls the base slug that will display before each term
'with_front' => false,
'hierarchical' => false
),
) );
}
add_action( 'admin_init', 'symbiostock_image_directory' );
function symbiostock_image_directory( )
{
add_meta_box( 'symbiostock-image-meta', 'Symbiostock Image Info', 'symbiostock_image_manager_meta_options', 'image', 'normal', 'high' );
}
以下是更下方的重写规则 -
add_action( 'init', 'symbiostock_rewrite' );
function symbiostock_rewrite( )
{
global $wp_rewrite;
$wp_rewrite->add_permastruct('typename','typename/%year%%postname%/' , true , 1);
add_rewrite_rule('typename/([0-9]{4})/(.+)/?$','index.php?typename=$matches[2]', 'top');
$wp_rewrite->flush_rules();
}