我有一个自定义的帖子类型,叫做rock
使用名为genero
. taxonomy-genero-curiosity.php
mypage/摇滚乐/好奇/
单击后续分页页面链接时(例如,[2]、[3]、[next])
mypage/摇滚乐/好奇心/第页/第2页
把我带到404页。
<?php
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
//for a given post type, return all
$args = array(
\'tax_query\' => array(
array(
\'taxonomy\' => \'genero\',
\'field\' => \'slug\',
\'terms\' => \'curiosity\'
)
),
\'post_type\'=>\'\', //add your post type name
\'posts_per_page\' => 1,
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
<?php wp_pagenavi( array( \'query\' => $my_query ) ); ?>
<?php wp_reset_postdata(); ?>
我怎样才能解决这个问题?我做错了什么?EDIT
下面是我如何注册我的帖子类型function my_custom_post_product() {
$labels = array(
\'name\' => _x( \'Rock\', \'post type general name\' ),
\'singular_name\' => _x( \'Rock\', \'post type singular name\' ),
\'add_new\' => _x( \'Add New\', \'entry in rock\' ),
\'add_new_item\' => __( \'Add New entry in rock\' ),
\'edit_item\' => __( \'Modificar entry in rock\' ),
\'new_item\' => __( \'New entry in rock\' ),
\'all_items\' => __( \'all entry in rock\' ),
\'view_item\' => __( \'see entry in rock\' ),
\'search_items\' => __( \'search entry in rock\' ),
\'not_found\' => __( \'Nothing entry in rock\' ),
\'not_found_in_trash\' => __( \'Nothing entry in rock on thrash\' ),
\'parent_item_colon\' => \'\',
\'menu_icon\' => get_bloginfo(\'template_directory\'). \'/images/my_menu_icon.png\',
\'menu_name\' => \'Rock\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Introduzca un nueva entrada en rock\',
\'public\' => true,
\'menu_position\' => 5,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\', \'comments\' ),
\'has_archive\' => true,
\'hierarchical\' => true,
\'rewrite\' => array(\'slug\' => \'Rock/%genero%\', \'with_front\' => false),
\'query_var\' => true,
//\'rewrite\' => true,
//\'publicly_queryable\' => false,
);
register_post_type( \'Rock\', $args );
}
add_action( \'init\', \'my_custom_post_product\' );
这是我现在的循环。我仍然得到这个代码的404错误<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<header>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p><time datetime="<?php echo get_the_date(); ?>"><?php echo get_the_date(); ?></time>. <?php if ( comments_open() ) : ?><a class="comment" href="<?php the_permalink(); ?>#comments"><?php comments_number(\'0 Comments\', \'1 Comment\', \'% Comments\'); ?></a><?php endif; ?></p>
</header>
<?php endwhile; else: ?>
<p><?php _e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>
<nav class="paging">
<?php if(function_exists(\'wp_pagenavi\')) : wp_pagenavi(); else : ?>
<div class="prev"><?php next_posts_link(\'« Previous Posts\') ?></div>
<div class="next"><?php previous_posts_link(\'Next Posts »\') ?></div>
<?php endif; ?>
</nav>
EDIT 2
我已经将camelcase“Rock”更改为“Rock”,并且可以工作,但只有在“管理”>“设置”>“阅读”中更改配置,并将post设置为显示为5,就像每页的post\\u数(在循环中),但如果我需要在其他页上显示较少的post\\u,例如post\\u per\\u page=3(例如,[2],[next]),则会出现404错误页。如果其他页面需要,是否有办法自定义数字?
<?php $posts=query_posts($query_string . \'&orderby=asc&posts_per_page=5\'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?$content = get_the_excerpt();
echo substr($content, 0, 200);
global $post;
$text = $post->post_excerpt;?>
<?php endwhile; else: ?>
<p><?php _e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>