我使用以下代码显示自定义帖子类型:
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php //query_posts('paged='.$paged);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('&posts_per_page=1'.'&paged='.$paged.'&post_type=blogpost&meta_key=category&meta_value='.$tempcat);
?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div>
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php endwhile; ?>
<div id="navigation">
<div id="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div id="alignright"><?php next_posts_link('Next Entries »','') ?></div>
</div>
<?php endif; // end have_posts() check ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer() ?>
此代码适用于每个页面,请执行主页。每当我点击下一个帖子链接时,我都会被重定向到404页面。有什么建议吗?
答案 0 :(得分:0)
将您的查询更改为:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=&paged=' . $paged);
?>
答案 1 :(得分:0)
你的问题出现在“wordpress查询帖子”中。如果您想了解更多阅读Function Reference/query posts ..现在尝试以下代码:
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('cat=&paged=' . $paged);
?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div>
<?php get_template_part( 'content', get_post_format() ); ?>
</div>
<?php endwhile; ?>
<div id="navigation">
<div id="alignleft"><?php previous_posts_link('« Previous Entries') ?></div>
<div id="alignright"><?php next_posts_link('Next Entries »','') ?></div>
</div>
<?php endif; // end have_posts() check ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer() ?>
祝你好运