我想做的是:
在自定义php模板文件中使用自定义WP\\U查询设置WP\\U查询分页(它原来不是我的,我只是在修复它)。文件在帖子中循环(类别“Publishing”)并将它们添加到页面中(一次添加5个)。
我的代码应该可以工作,它似乎做得很好,并且遵循WP文档。我想知道是什么bug阻止了它的工作。
我所做的尝试是用paginate\\u链接(数组)添加分页。我确实得到了分页栏,但每次我点击一个链接,它都会跳回主页。但url中添加了一个/页/2/等。
尝试了WP-PageNavi 添加的插件:$custom_query->query(array(\'category_name\' => \'Publishing\', \'page\' => get_query_var(\'paged\')));
并使用短代码:
wp_pagenavi(array( \'query\' => $custom_query ) );
结果与1)中的结果相同。它总是跳回主页,但会将slug添加到URL。
我要做的是在页面底部添加一个有效的分页。我想我的模板中循环的工作方式可能存在一些问题?
My current code with the WP-PageNavi plugin:
<?php
$args = array(
"category_name" => "Publishing",
"orderby" => "post_date",
"order" => "DESC",
"post_type" => "post",
"post_status" => "publish",
);
$custom_query = new WP_Query($args);
$custom_query->query(array(\'category_name\' => \'Publishing\', \'page\' => get_query_var(\'paged\')));
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post();
{ $id=$post->ID; $image=get_the_post_thumbnail($id, \'full\');
if( class_exists(\'Dynamic_Featured_Image\') ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images($id );
}
echo "<div class=\'direkt\'>".get_the_date( \'d F Y\', $post->ID )."<a href=".get_permalink($post->ID)."?kat=publishing> [Direct Link] </a></div>";
?>
<div class="custompost_wrapper">
<div class="custompost">
<div class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<?php echo $image; ?>
</li>
<?php foreach($featured_images as $featured_image): ?>
<li class="splide__slide">
<img src="<?php echo $featured_image[\'full\']; ?>"
data-splide-lazy="<?php echo $featured_image[\'full\']; ?>"
loading="lazy"
>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
</div>
<?php
echo "<div class=\'custompost_contentwrapper\'><strong>";
the_title();
echo "</strong><br>";
echo "<div class=\'thecontent\'>";
the_content();
echo "</div>";
echo "<div class=\'spacer\'></div></div>";
}
endwhile;
wp_pagenavi(array( \'query\' => $custom_query ) );
wp_reset_postdata();
endif;
?>
The method I tried before the plugin:
<?php
$published_posts = wp_count_posts()->publish;
$posts_per_page = get_option(\'posts_per_page\');
$page_number_max = ceil($published_posts / $posts_per_page);
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
"category_name" => "Publishing",
"orderby" => "post_date",
"order" => "DESC",
"post_type" => "post",
"post_status" => "publish",
);
$custom_query = new WP_Query($args);
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post();
{ $id=$post->ID; $image=get_the_post_thumbnail($id, \'full\');
if( class_exists(\'Dynamic_Featured_Image\') ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images($id );
}
echo "<div class=\'direkt\'>".get_the_date( \'d F Y\', $post->ID )."<a href=".get_permalink($post->ID)."?kat=publishing> [Direct Link] </a></div>";
?>
<div class="custompost_wrapper">
<div class="custompost">
<div class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<?php echo $image; ?>
</li>
<?php foreach($featured_images as $featured_image): ?>
<li class="splide__slide">
<img src="<?php echo $featured_image[\'full\']; ?>"
data-splide-lazy="<?php echo $featured_image[\'full\']; ?>"
loading="lazy"
>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
</div>
<?php
echo "<div class=\'custompost_contentwrapper\'><strong>";
the_title();
echo "</strong><br>";
echo "<div class=\'thecontent\'>";
the_content();
echo "</div>";
echo "<div class=\'spacer\'></div></div>";
}
endwhile;
$total_pages = $page_number_max;
if ($total_pages > 1){
$current_page = max(1, get_query_var(\'paged\'));
echo paginate_links(array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'format\' => \'page/%#%\',
\'current\' => $current_page,
\'total\' => $total_pages,
\'prev_text\' => __(\'« prev\'),
\'next_text\' => __(\'next »\'),
));
};
wp_reset_postdata();
endif;
?>
Any help would be appreciated. I\'m trying to get the pagination to work for hours now.