0
<?php query_posts('showposts=5&post_type=html5-blank'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>" class="clearfix" <?php post_class(); ?>>
           //Loop Here
    <!-- /Article -->

<?php endwhile; ?>
<nav>
    <?php previous_posts_link('&laquo; Newer') ?>
    <?php next_posts_link('Older &raquo;') ?>
</nav>

<?php 
  $wp_query = null; 
  $wp_query = $temp;  // Reset
?>

Page doesn't existページネーション リンクでエラーが発生します。結果リンク:www.mywebsite.com/blog/page/2/ これはブログページです。ループコードを編集しました。

ヘルプ.........

4

4 に答える 4

2

投稿を一覧表示するホームページ(index.php)でも同様の問題が発生しました。ページが見つかりません。https://codex.wordpress.org/Paginationの説明で、www.domain.com / page/2/が機能しました。

まず、テンプレートファイル(index.php、category.php)からquery_posts部分を削除します

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 3, 'paged' => $paged );
query_posts($args);

次に、functions.phpに以下を追加します

function my_post_queries( $query ) {
    // do not alter the query on wp-admin pages and only alter it if it's the main query
    if (!is_admin() && $query->is_main_query()){
        // alter the query for the home and category pages
        if(is_home()){
            $query->set('posts_per_page', 3);
        }
        if(is_category()){
            $query->set('posts_per_page', 3);
        }
    }
]
add_action( 'pre_get_posts', 'my_post_queries' );

注:HTML5の空白のテーマとアンダースコアのテーマの両方で、ページネーションで404エラーが発生しました。上記のソリューションでは、両方のテーマでページネーションが機能しました。

于 2013-03-09T05:23:00.337 に答える
1

私はむしろページネーションパラメータWP_Queryを使用して使用したいと思います。これについて詳しくは、 WP_Query#Pagination_Parameterspagedをご覧ください。

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query(
    array(
        'post_type' => 'html5-blank',
        'posts_per_page' => 5,
        'paged'=>$paged
    )
);
?>
<?php if ($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); ?>
    <article id="post-<?php the_ID(); ?>" class="clearfix" <?php post_class(); ?>>
           //Loop Here
    <!-- /Article -->

<?php endwhile; endif; ?>
<nav>
    <?php previous_posts_link('&laquo; Newer') ?>
    <?php next_posts_link('Older &raquo;') ?>
</nav>

私にお知らせください :)

2番目の例:

global $post;
global $paged, $wp_query;
$args = array( 'posts_per_page' => 5, 'post_type' => 'html5-blank', 'paged' => $paged );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
    setup_postdata($post);
    // loop
    the_title(); // or what it is needed inside the loop
endforeach;
if (  $wp_query->max_num_pages > 1 ) :
    previous_posts_link('&laquo; Newer');
    next_posts_link('Older &raquo;');
endif;
于 2013-01-29T09:28:31.127 に答える
0
<?php
global $wp_query;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(  
            'post_type' => 'html5-blank', //Post type
            'posts_per_page' => 5, //How many post u want to display per page
            'paged' => $paged                      
            );
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
    $the_query->the_post();

    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
    <img src="<?=$url?>" width="350" height="350" class="thumbnail imageRight"/>
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <p><?php the_excerpt(); ?></p>

<?php } } ?>
<div class="pagination">
<?php             
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
    ) );
?>
</div>
于 2014-12-25T17:07:38.687 に答える