4

好的,我正在为此扯掉我的头发,我知道它非常简单,并且正盯着我的脸,但我就是看不到它。本质上,正在发生的事情是我的分页不起作用。我使用插件 wp_pagenavi (这不是已经检查过的问题)它为我提供了分页中每个页面的链接列表。这一切都很好,事实上所有的代码都做了它应该做的事情。问题是当我单击分页链接(例如“2”或“3”)时,它会尝试转到相应的分页,即 www.yousitehere.com/somepage/page/2 但该站点只是重新加载当前页面而没有/第2页。

我认为页面的某个地方要么没有意识到它需要分页,因此忽略了 /page 的所有实例,或者在页面加载之前正在重置分页。(它不是reset_query)。

这是一个 Wordpress 网站。不幸的是,我无法显示网站链接,这让你更难,希望有人有建议。

这是我的代码

<div id="content" class="clearfix">
<div id="main" class="col960 left first clearfix" role="cont_detail">
<?php if (have_posts()) : while (have_posts()) : the_post(); 
    $id = get_the_ID();
    $array = metadata($id);
?>
    <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="cont_detail" >
        <header>
            <div id="header_bg_top"></div>
            <div id="header_bg">
                <?php if($array['custom_facebook'] !="" && $array['custom_twitter'] !="" && $array['custom_linkedin'] != ""&& $array['custom_website'] != "" && $array['custom_blog'] != "" && $array['custom_email'] != ""){?>
                <div class="social_link_container">
                    <div class="width">
                        <?php if(isset($array['custom_facebook']) && $array['custom_facebook'] !=""){?>
                        <a href="http://www.facebook.com/<?php echo $array['custom_facebook'];?>" target="_new"><img src="<?php echo get_template_directory_uri(); ?>/images/author-facebook.png"></a>
                        <?php  }
                        if(isset($array['custom_twitter']) && $array['custom_twitter'] !=""){?>
                        <a href="http://www.twitter.com/<?php echo $array['custom_twitter'];?>" target="_new"><img src="<?php echo get_template_directory_uri(); ?>/images/author-twitter.png"></a>
                        <?php  }
                        if(isset($array['custom_linkedin']) && $array['custom_linkedin'] !=""){?>
                        <a href="http://www.linkedin.com/<?php echo $array['custom_linkedin'];?>" target="_new"><img src="<?php echo get_template_directory_uri(); ?>/images/author-in.png"></a>
                        <?php  }
                        if(isset($array['custom_website']) && $array['custom_website'] !=""){?>
                        <a href="http://<?php echo $array['custom_website'];?>" target="_new"><img src="<?php echo get_template_directory_uri(); ?>/images/author-web.png"></a>
                        <?php  }
                        if(isset($array['custom_blog']) && $array['custom_blog'] !=""){?>
                        <a href="http://<?php echo $array['custom_blog'];?>" target="_new"><img src="<?php echo get_template_directory_uri(); ?>/images/author-blog.png"></a>
                        <?php  }
                        if(isset($array['custom_email']) && $array['custom_email'] !=""){?>
                        <a href="mailto:<?php echo $array['custom_email'];?>"><img src="<?php echo get_template_directory_uri(); ?>/images/author-email.png"></a><?php  }?>
                    </div>
                </div>
                <?php } ?>
                <h1 class="cont_detail_title" itemprop="headline"><?php the_title(); ?></h1>
                <?php if(isset($array['custom_description']) && $array['custom_description'] !="")
                {
                    ?>
                    <span class="title_description"><?php echo $array['custom_description']; ?></span>
                <?php
                }
                ?>
            </div><!-- header-bg -->
        </header> <!-- end article header -->
        <section>
            <div class="content-left">
                <?php if(isset($array['featured_thumb']) && $array['featured_thumb'] !="")
                    {
                    ?>
                    <div class="cont_detail_image">
                        <?php print_thumbnail($array['featured_thumb'], "medium");?>
                    </div>
                <?php  
                }
                ?>
            </div>
            <div class="content-right">
                <?php the_content(); ?>
            </div>
        </section> <!-- end article section -->

    </article> <!-- end article -->
    <?php endwhile; ?>          
    <?php else : ?>
        <article id="post-not-found">
            <header>
                <h1>Not Found</h1>
            </header>
            <section class="post_content">
                <p>Sorry, but the requested resource was not found on this site.</p>
            </section>
            <footer>    
            </footer>
        </article>
    <?php endif;        
    wp_reset_query();
//Sort queries, most viewed, alphabetical, date         

    echo '<section><div id="content_bg" class="group">';
    $row_num = 1;            
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                     
    if( $_GET['sort'] == 'date' ) {
        $sortOrder = getSortOrder( $_GET['dsort_order'] );
        $meta_queries[] = array(                
            'key' => 'custom_authorid',
            'value' => $post->ID,
            'compare' => 'LIKE',
            );
            query_posts(array(
            'post__not_in' => array($post->ID),
            'post_type' => 'post',
            'meta_query' => $meta_queries,
            'order'=>$sortOrder,
            'orderby'=> 'date',
            'posts_per_page' => 9,
            'paged' => $paged
            ));
    }
    elseif( $_GET['sort'] == 'alpha' ) {
        $sortOrder = getSortOrder( $_GET['asort_order'] );
        $meta_queries[] = array(                
            'key' => 'custom_authorid',
            'value' => $post->ID,
            'compare' => 'LIKE',
            );
            query_posts(array(
            'post__not_in' => array($post->ID),
            'post_type' => 'post',
            'meta_query' => $meta_queries,
            'order'=>$sortOrder,
            'orderby'=> 'title',
            // adding posts_per_page, set to 9 might be different then global preference
            'posts_per_page' => 9,
            'paged' => $paged
            ));
        }
    elseif( $_GET['sort'] == 'mviewed' ) {

        }
    else{   
        $meta_queries[] = array(                                                
            'key' => 'custom_authorid',
            'value' => $post->ID,
            'compare' => 'LIKE',
            );
            query_posts(array(
            'post__not_in' => array($post->ID),
            'post_type' => 'post',
            'posts_per_page' => 9,
            'meta_query' => $meta_queries,
            'paged' => $paged
            ));
        }

        ?>
    <div class="paginate_nav">
        <?php wp_pagenavi(); // use the page navi function ?>
        <div class="sort_nav">
            <?php contrPaginationLinks( $sortOrder ) ?>
        </div><!--sort_nav-->
    </div><!--paginate_nav-->       
    <?php 
        if( $_GET['sort'] == 'mviewed' ) {

        }
        else{ 
            if (have_posts()) : while (have_posts()) : the_post();                                          
                $item = metadata($post->ID);
                $containsVideos = false;
                foreach ($item['cat'] as $value) {
                    if (strpos($value->cat_name,'Videos') !== false) {
                        $containsVideos = true;
                    }
                }
             ?>
                <div class="story-container" >
                    <div class="story_left">
                        <div class="story_image">
                            <input type="hidden" name="vidID" value="<?php echo $item['media_link']; ?>" />
                            <div class="about_latest_image <?php echo $item['media_link']; ?>">
                                <a href="<?php echo $item['link']; ?>">
                                        <?php
                                        print_thumbnail($item['featured_thumb'],"thumbnail", $item['youtube_link'], $item['vimeo_link'], $item['media_link']);      
                                        ?>
                                    <?php if($containsVideos == true){echo '<span class="videoIndicator"></span>';} ?>
                                </a>        
                            </div>
                        </div>      
                        <?php if($_GET['sort'] == 'date'){ ?>
                            <div class="story_view">
                                <?php echo $item['date']; ?>
                            </div>
                            <?php } ?>
                    </div>
                <div class="story_title">
                    <a href="<?php echo $item['link']; ?>" title="<?php echo $item['title']; ?>"> 
                        <span class="story_title"><?php echo $item['title']; ?></span>
                    </a>
                </div>
                <?php if(isset($item['custom_description']) && $item['custom_description'] !="") {
                ?>
                    <div class="story_description"><?php echo $item['custom_description']; ?></div>
                <?php  
                }
                ?>
            <div class="story_content"></div>                         
        </div>
        <?php endwhile; ?>  
        <?php else : ?>
            <h1><?php _e("No Posts Yet", "hooplahatheme"); ?></h1>
            <p><?php _e("Sorry, What you were looking for is not here.", "hooplahatheme"); ?></p>
        <?php endif; 
        } // end display else default
        echo '</div></section>';
        //
        // reset query after display is done            
        //
        wp_reset_query();
        ?>
        <footer>
        </footer> <!-- end article footer -->
</div> <!-- end #main -->    


更新

事实证明,发生了一个 302 重定向,这是我试图找出的下一步。

4

2 回答 2

4

克里斯托弗的回答可能适用于大多数人。

但..

如果您想阻止重定向也影响/pagename/page/1,这将有所帮助:

add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2); 
function my_redirect_canonical($redirect_url, $requested_url) { 
  $do_redirect = true; 
  if(preg_match('/page/',$requested_url)){
    $do_redirect = false; 
  }
  return $do_redirect; 
} 

在这里找到。

于 2014-02-25T04:02:19.673 回答
3

因此,对于任何有类似问题的人来说,答案很简单。默认情况下,您不能在 wordpress 中对单个帖子页面进行分页。它只会重定向回页面的根 URL。您需要做的就是将其添加到您的主题 functions.php

add_filter('redirect_canonical','pif_disable_redirect_canonical');

function pif_disable_redirect_canonical($redirect_url) {


if( is_singular() && in_category('PLACE CAT ID HERE') ) {
    $redirect_url = false;
}
return $redirect_url;
}

有关这方面的更多信息,您可以在这里查看http://wordpress.org/support/topic/home-pagination-page2-redirect-to-a-post

于 2012-12-29T04:47:31.750 回答