我希望我的分页功能能正常工作

时间:2017-07-17 作者:birdistheword

当我单击分页中的任意链接时,它会显示一个空白页。向前和向后工作。显示的已发布帖子数量减少了两个。请帮忙。

<?php 

$per_page = 5; 

$connection = mysqli_connect(\'localhost\',\'root\',\'root\',\'wordpress\');

 if($connection){
     echo \'connected to the database\';
 }

 else {
    echo \'not connected to the database\';
 }


?>


<?php
if(isset($_GET[\'page\'])){

$page = $_GET[\'page\'];

} else {

    $page = "";
}

if($page == "" || $page == 1) {

    $page_1 = 0;

} 

else {
    $page_1 = ($page * 5) - 5;
}


?>


<?php
$post_query_count = "SELECT * FROM wp_posts";
$find_count = mysqli_query($connection,$post_query_count);
$count = mysqli_num_rows($find_count);

$count = ceil($count / $per_page);
echo $count;


$query = "SELECT * FROM wp_posts LIMIT $page_1, 5";
$select_all_posts_query = mysqli_query($connection,$query);

while($row = mysqli_fetch_assoc($select_all_posts_query)) {
$post_id = $row[\'ID\'];  // is this post_id or ID?
$post_title = $row[\'post_title\']; //
$post_author = $row[\'post_author\']; //
$post_date = $row[\'post_date\']; //
$post_image = $row[\'post_image\']; 
$post_content = substr($row[\'post_content\'],0,400); //
$post_status = $row[\'post_status\']; //

if($post_status == \'published\'){ } 


}

?>

<h1><?php echo \'total blog post\' . "" . $count ?></h1>


<!-- below is the default wordpress php loop code block --> 



<?php if (have_posts()) : ?>

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


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

        <!--beginning of  title above -->

            <!-- blog Headers below -->
            <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

        <!--end of  title above -->




            <!-- Featured image -->
            <div class="entry">

            <!-- date posted on and by the author -->
           <?php include (TEMPLATEPATH . \'/inc/meta.php\' ); ?> 

                <a href="<?php the_permalink(); ?>">

            <div class="blogInsert"><?php the_post_thumbnail(\'small-thumbnail\'); ?></a></div>

                <?php the_content(\'Continue reading &raquo;\'); ?>

            </div><!--end of the blog entry-->



            <!-- beginning of entry is either featured image or the middle piece-->


            <!--begin of the catagorized & comments -->
            <div class="postmetadata">
                <?php the_tags(\'Tags: \', \', \', \'<br />\'); ?>
                Posted in <?php the_category(\', \') ?> | 
                <?php comments_popup_link(\'No Comments &#187;\', \'1 Comment &#187;\', \'% Comments &#187;\'); ?>

            </div>
            <!--end of the catagorized & comments -->


        </div><!--end of blogEntry-->

    <?php endwhile; ?>

<?php next_posts_link(\'Older Entries\'); ?>

<?php previous_posts_link(\'Newer Entries\'); ?>

    <?php else : ?>

    <h2>Not Found</h2>
    <?php endif; ?>

        <?php 
        $ourCurrentPage = get_query_var(\'paged\');
        $aboutPosts = new WP_query(array(\'category_name\' => \'about\', \'posts_per_page\' => 5, \'paged\' => $ourCurrentPage )); ?>
<ul class="paging-navigation">

<br>
<br>

<?php


for($i =1; $i <= $count; $i++) {

echo "<li><a href=\'index.php?page={$i}\'>{$i}</a></li>";

}

?>

</ul>

1 个回复
SO网友:Greeso

Try $_GET[\'paged\'] instead of $_GET[\'page\']

结束

相关推荐

Pagination - not progressing

好的,我添加了以下分页标记:<?php next_posts_link( \'Older posts\' ); ?> <?php previous_posts_link( \'Newer posts\' ); ?> 我可以在地址栏中看到查询字符串正在正确更改e、 g.localhost:8888/wordpress/?页码=3但是,页面结果保持不变(显示最初的前10个结果)。我这里出了什么问题?编辑:下面是代码(没有任何HTML):<!--Latest Po