【发布时间】:2014-09-19 15:25:21
【问题描述】:
我有自定义帖子类型。 永久链接看起来像 /%postname%
我的 CPT 功能:
function cpt_lyrics() {
$labels = array(
'name' => _x( 'Lyrics', 'Post Type General Name', 'Lyrics' ),
'singular_name' => _x( 'Lyrics', 'Post Type Singular Name', 'Lyrics' ),
'menu_name' => __( 'Lyrics', 'Lyrics' ),
'parent_item_colon' => __( 'Parent Lyrics:', 'Lyrics' ),
'all_items' => __( 'All Lyrics', 'Lyrics' ),
'view_item' => __( 'View Lyrics', 'Lyrics' ),
'add_new_item' => __( 'Add New Lyrics', 'Lyrics' ),
'add_new' => __( 'Add New', 'Lyrics' ),
'edit_item' => __( 'Edit Lyrics', 'Lyrics' ),
'update_item' => __( 'Update Lyrics', 'Lyrics' ),
'search_items' => __( 'Search Lyrics', 'Lyrics' ),
'not_found' => __( 'Not found', 'Lyrics' ),
'not_found_in_trash' => __( 'Not found in Trash', 'Lyrics' ),
);
$args = array(
'label' => __( 'lyrics', 'Lyrics' ),
'description' => __( 'Lyrics Name', 'Lyrics' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'page-attributes', 'post-formats', ),
'taxonomies' => array( 'bands', 'albums' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 7,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'lyrics', $args );
}
分页功能有效,但它显示如下链接:domain.com/page/2,我收到错误 404。 但是这些页面在 url 上可用,例如:domain.com/?page=2。 为什么会这样?
【问题讨论】:
-
您是否更改了管理员中的永久链接结构?
-
是的,在管理面板中,不是 .htaccess
-
你能从你的循环中发布查询吗?
-
当然,
<?php if ( get_query_var('paged') ) $paged = get_query_var('paged'); elseif ( get_query_var('page') ) $paged = get_query_var('page'); else $paged = 1; $wp_query = new WP_Query(array( 'post_type' => 'lyrics', 'posts_per_page' => 12, 'paged' => $paged )); while ( $wp_query->have_posts() ) : $wp_query->the_post();?> -
不太确定该查询。试试
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } query_posts('posts_per_page=12&post_type=lyrics&paged=' . $paged);
标签: wordpress function pagination http-status-code-404