分页无法链接到第2页wordpress?

时间:2015-12-09 04:31:45

标签: wordpress wordpress-theming

大家好我的第2页链接分页问题我安装了插件Wp-pagnavi,当我点​​击链接到第2页时它不显示内容页面2,它仍然停留在第1页,我该如何解决这个问题。

你可以看到它 http://westecmedia.com/?page_id=758

这是我的代码博客帖子页面:

<?php
/*
 *  Template Name: Page - Events Page
 */
?>

<?php get_header(); ?>

<div id="content-events">
    <div id="head-event"><h3>EVENTS</h3></div>
    <div id="main-event">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <?php the_content(); ?>

    <?php endwhile; else: endif; ?>

    <?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div id="part-event">
    <div id="entry-thumbnail">
            <?php the_post_thumbnail(); ?>

    </div>
    <div id="event-dess">
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <p>
            <?php 
            $content = get_the_content();
            $content = strip_tags($content);
            echo substr($content, 0, 300);
            ?>
        </p>
        <div id="read-more"><a href="<?php the_permalink(); ?>">Read More</a></div>
    </div>

</div>
        <div id="line-bottom"></div>
    <?php endwhile; else: endif; ?>
        <?php wp_pagenavi(); ?>

    </div>
</div>

<?php get_footer(); ?>

请帮帮我?

2 个答案:

答案 0 :(得分:3)

您应该将所有这些放在一个循环中并设置wp_reset_query();,并且还必须在paged中每页使用query_post选项。 试试这个

<?php
/*
 *  Template Name: Page - Events Page
 */
?>

<?php get_header(); ?>
<div id="content-events">
    <div id="head-event"><h3>EVENTS</h3></div>
    <div id="main-event">

                <?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=3&paged=' . $paged,category_name='.get_the_title().'&post_status=publish,future');?>

                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <div id="part-event">
                            <div id="entry-thumbnail">
                                    <?php the_post_thumbnail(); ?>

                            </div>
                            <div id="event-dess">
                            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <p>
                                    <?php 
                                    $content = get_the_content();
                                    $content = strip_tags($content);
                                    echo substr($content, 0, 300);
                                    ?>
                                </p>
                                <div id="read-more"><a href="<?php the_permalink(); ?>">Read More</a></div>
                            </div>

                    </div>
                    <div id="line-bottom"></div>
                <?php endwhile; endif; ?>
                    <?php wp_pagenavi(); ?>

                    <?php wp_reset_query(); ?>


    </div>
</div>
<?php get_footer(); ?>

答案 1 :(得分:2)

<?php
$args = array(
    'cat' => '5',
    'post_type' => 'post',
    'posts_per_page' => 6,
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
 /* Do whatever you want to do for every page... */
endwhile;
wp_pagenavi();
wp_reset_query();  // Restore global post data
?>