我有定制的邮政类型。Permalinks看起来像/%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。为什么会发生这种情况?
发布于 2014-07-30 07:12:40
也许它会对某人有用..。将其添加到functions.php中:
function my_post_queries( $query ) {
if (!is_admin() && $query->is_main_query()){
$taxonomies = array ('YOUR_TAXONOMY');
if(is_tax($taxonomies) || is_home()) {
$query->set ('post_type', 'YOUR_POST_TYPE');
}
}
}
add_action( 'pre_get_posts', 'my_post_queries' );发布于 2014-07-28 12:37:03
您需要在循环上面添加分页查询,以使分页对我认为的自定义Post类型有效。
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=3&paged=' . $paged);
?>或
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);发布于 2014-07-28 12:49:31
https://stackoverflow.com/questions/24995277
复制相似问题