分页问题:索引中的自定义帖子类型

时间:2012-07-31 作者:Alejandro Hernández

我使用的是一个模板,它使用自定义的Post类型“movies”。当我尝试更改页面时,发现404未找到:(

这是我的索引。php

<div id="content">
<?php
$temp = $wp_query;
$page = get_query_var(\'page\');
$page = (!empty($page) ? $page : 1);
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(\'post_type=movies\'.\'&posts_per_page=6&paged=$page\');
?>
<?php while (have_posts()) : the_post(); ?> 

<div class="box " id="post-<?php the_ID(); ?>">

<div class="boxentry">
<div class="btitle">
    <h2 align="center"><a href="<?php the_permalink() ?>" rel="bookmark" title="Ver <?php the_title(); ?>"><?php echo get_post_meta($post->ID, \'wtf_ryear\', true); ?></a></h2>
</div>
<!--div class="clear"></div-->
</div>

<div class="boxim">
<?php
if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink() ?>"><img class="boximg" src="<?php bloginfo(\'stylesheet_directory\'); ?>/timthumb.php?src=<?php get_image_url(); ?>&amp;h=270&amp;w=180&amp;zc=1" alt=""/></a>
<?php } else { ?>
    <a href="<?php the_permalink() ?>"><img class="boximg" src="<?php bloginfo(\'template_directory\'); ?>/images/dummy.png" alt="" /></a>
<?php } ?>

</div>

</div>

<?php if(++$counter % 4 == 0) : ?>
<div class="clear"></div>
<?php endif; ?>

<?php endwhile; ?>

<div class="clear"></div>
<?php getpagenavi(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div>
这是我的帖子类型:

function post_type_movies() {
register_post_type(
\'movies\', 
array( \'public\' => true,
        \'publicly_queryable\' => true,
        \'has_archive\' => true, 
        \'hierarchical\' => false,
        \'menu_icon\' => get_stylesheet_directory_uri() . \'/images/movie.png\',
        \'labels\'=>array(
            \'name\' => _x(\'Movies\', \'post type general name\'),
            \'singular_name\' => _x(\'Movie\', \'post type singular name\'),
            \'add_new\' => _x(\'Add New\', \'Movies\'),
            \'add_new_item\' => __(\'Add New Movie\'),
            \'edit_item\' => __(\'Edit Movie\'),
            \'new_item\' => __(\'New Movie\'),
            \'view_item\' => __(\'View Movie\'),
            \'search_items\' => __(\'Search Movies\'),
            \'not_found\' =>  __(\'No Movies found\'),
            \'not_found_in_trash\' => __(\'No Movie found in Trash\'), 
            \'parent_item_colon\' => \'\'
            ),                           
        \'show_ui\' => true,
        \'menu_position\'=>5,
        \'query_var\' => true,
        \'rewrite\' => TRUE,
        \'rewrite\' => array( \'slug\' => \'pelicula\', \'with_front\' => FALSE,),
        \'register_meta_box_cb\' => \'mytheme_add_box\',
        \'supports\' => array(
            \'title\',
            \'thumbnail\',
            \'comments\',
            \'editor\'
            )
        ) 
);
} 
add_action(\'init\', \'post_type_movies\');
点击查看http://ddlpremium.com/peliculeros

提前谢谢。

2 个回复
SO网友:Sisir

Couple of small corrections:

$wp_query 是一个全局变量,因此需要将其作为全局变量进行清除,我相信查询变量是pagedpage. 所以

改变

$temp = $wp_query;
$page = get_query_var(\'page\');

global $wp_query;
$temp = $wp_query;
$page = get_query_var(\'paged\');
检查是否有效。此外,我更喜欢用单数表示CPT名称。movie 而不是movies.

SO网友:nvwd

您是否尝试过在变量的查询字符串周围使用双引号?

更改:

$wp_query->query(\'post_type=movies\'.\'&posts_per_page=6&paged=$page\');

$wp_query->query(\'post_type=movies\'."&posts_per_page=6&paged=$page");
如果这不能解决问题,请尝试在上述代码之后转储查询var_dump( $wp_query ) 它可能会显示问题的原因。

结束

相关推荐

Pagination for sub-pages

我有一个顶级页面,有很多子页面当用户访问顶级页面时,他们当前会看到标题/缩略图/摘录all 子页面的如何分页子页面的显示,以便only 每次显示3,使用户可以通过典型的“上一页1、2、3、4、5下一页>”分页菜单进行导航?任何帮助都将不胜感激。谢谢