分页在wp Blog中不起作用

时间:2014-08-19 09:09:05

标签: php html wordpress

    <?php 
        $args=array(
        'post_type'=>'post',
        'cat' => '',
        'posts_per_page' => 4,
        'paged'=>$paged
        );
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query($args);
        if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();  ?>

    <div id="box1">

    <h1 class="blog1"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <h2 class="blog2">Posted By :- <?php the_author_meta('display_name'); ?> <span class="blog3">
        <?php echo get_the_date(); ?></span></h2>
        <?php $a=wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>  
        <span class="blog4"><img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $a; ?>&w=200&h=150&q=100" alt=""></span>
        <p class="blogcontent"><?php $a=get_the_content();
            $b=strlen($a);
            if($b>770)
                {
                    $con = substr($a, 0, strrpos(substr($a,0,770),' ')).  '....';
                    echo $con;          
                ?>
                <p style=" float:right;"><a style ="margin-top:15px;" href="<?php echo get_permalink($post->ID);?> ">Read More</a></p>
        <?php
                }
                else
                {
                    echo $a;                
                }           
            ?>
            </p>
    </div>

<?php //endforeach; 
 endwhile; ?>
<?php endif; ?>

<span style="padding:30px;"><?php if(function_exists('wp_paginate')) {wp_paginate();} 
$wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
</span>

我在wordpress博客上工作并在博客中加入了分页中的问题。当点击第2页时,网址更改但页面未更改。我正在使用以下代码     谢谢&amp;此致

1 个答案:

答案 0 :(得分:0)

试试这段代码:

<?php 
        $args=array(
        'post_type'=>'post',
        'cat' => '',
        'posts_per_page' => 4,
        'paged'=>$paged
        );
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query($args);
        if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();  ?>

    <div id="box1">

    <h1 class="blog1"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
        <h2 class="blog2">Posted By :- <?php the_author_meta('display_name'); ?> <span class="blog3">
        <?php echo get_the_date(); ?></span></h2>
        <?php $a=wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>  
        <span class="blog4"><img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $a; ?>&w=200&h=150&q=100" alt=""></span>
        <p class="blogcontent"><?php $a=get_the_content();
            $b=strlen($a);
            if($b>770)
                {
                    $con = substr($a, 0, strrpos(substr($a,0,770),' ')).  '....';
                    echo $con;          
                ?>
                <p style=" float:right;"><a style ="margin-top:15px;" href="<?php echo get_permalink($post->ID);?> ">Read More</a></p>
        <?php
                }
                else
                {
                    echo $a;                
                }           
            ?>
            </p>
    </div>

<?php //endforeach; 
 endwhile; ?>
<?php endif; ?>

<span style="padding:30px;">

<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

$wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
</span>

或者,如果您想要编号,可以查看this教程。

相关问题