我使用的代码改编自this example 并在我的本地主机上成功测试,但当我将站点传递到实时服务器时,分页会在wordpress permalinks集(/%postname%/)下崩溃,并且只适用于默认的wp permalinks(?p=123)。问题是它没有显示任何404页,但它也不允许我转到第二页或第三页,或者任何其他页(如果存在的话)。
这是一个列表(自定义postype)页面(single listing.php),我的页面如下所示:
当前单一上市内容
- 我做了一些研究,甚至尝试替换“paged”,因为分页存档和单个帖子的查询变量应该使用“page”并遵循@pietergoosen 关于的提示this notice 通过打开mysql。本地php中的trace\\u模式。ini。之后,我重新启动了wampp中的所有服务,并且localhost上的分页工作正常,所以我认为这可能不是问题所在。
这是我的代码:
<?php
global $authordata, $post;
$paged = ( get_query_var(\'page\') ) ? get_query_var(\'page\') : 1;
$args = array(
\'author\' => $authordata->ID,
\'post_type\' => \'post\',
\'post__not_in\' => array( $post->ID ),
\'posts_per_page\' => 3,
\'paged\' => $paged
);
$authors_posts = new WP_Query( $args );
if( $authors_posts->have_posts()) : while( $authors_posts->have_posts()) :
$authors_posts->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a>
<?php the_post_thumbnail( array(80,135));?>
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,40);?>
<?php endwhile; ?>
<?php if($authors_posts->max_num_pages)
if(function_exists(\'wp_pagenavi\'))
wp_pagenavi(array(
\'query\' =>$authors_posts
)); ?>
<?php endif; wp_reset_query(); ?>
EDIT
我已选择@pietergoosen 答案是解决了我的问题,但我不明白为什么我的代码停止在实时服务器上工作。现在,我可能永远不会使用这些信息,但我肯定想知道为什么我的代码在本地主机(使用wampserver)上工作,而不是在实时服务器上工作。。。如果你知道这个问题的答案,请发表评论。谢谢