因此,我一直在將自己的主题發展為學習经驗,而我對如何使分頁工作感到困惑.在到達這一點之前,我已经尝試了几件事,並問,我似乎只是缺少了某物。
這是在"靜態首頁"上,這就是$ paged至少呼叫" page"的原因,這就是我的研究發現的一件事。
<?php while ( have_posts() ) : the_post(); ?>
<h2>Recent Posts</h2>
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$Post = array(
'post_type' => 'post',
'posts_per_page' => 4,
'orderby' => 'modified',
'order' => 'DESC',
'paged' => $paged
);
$q = new WP_Query( $Post );
?>
<div class="grid row posts">
<?php while ( $q->have_posts() ) : $q->the_post(); ?>
<div class="col">
<div class="date-container">
<p class="post-date bg-darkpurple">
<?php
//echo get_the_date()
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "Last updated ";
the_modified_time('F jS, Y');
echo ""; }
else {echo "Posted "; the_time('F jS, Y');}
?>
</p>
</div>
<?php
$perma_cat = get_post_meta($post->ID , '_category_permalink', true);
if ( $perma_cat != null ) {
$cat_id = $perma_cat['category'];
$category = get_category($cat_id);
} else {
$categories = get_the_category();
$category = $categories[0];
}
$category_link = get_category_link($category);
$category_name = $category->name;
?>
<picture class="post-thumb block">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a>
<div class="cat-container">
<a class="post-cat bg-darkpurple" href="<?php echo $category_link ?>"><?php echo $category_name ?></a>
</div>
</picture>
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php echo '<p class="excerpt">' . get_the_excerpt(). '</p>'; ?>
</div>
<?php endwhile; ?>
</div>
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'page' ) ),
'format' => '?page=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => true,
'prev_text' => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
'next_text' => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
'add_args' => false,
'add_fragment' => '',
) );
?>
</div>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?>
感谢您提供任何见識
最新回復
- 2020-1-181 #
相似問題
- wordpress:在shortcode屬性中返迴多个值wordpresspluginswordpressphpwordpresswpquerywordpressfunctionswordpressshortcode2020-12-03 23:28
- wordpress:如何根据查詢頁面/帖子?wordpressphpwordpresswpquerywordpressarchiveswordpressslug2020-11-21 08:22
- wordpress:wP_Query中每種帖子型別的不同選項wordpresscustomposttypeswordpressphpwordpresswpquerywordpresscustomtaxonomy2020-11-12 00:54
- wordpress:如何在wordPress中使用AJAX請求更改PHP變數wordpressphpwordpressthemedevelopmentwordpressajaxwordpressjquery2020-08-25 04:54
- wordpress:wP_QUERy post_in問题wordpressphpwordpresswpquery2020-07-23 04:24
- wordpress:如何在子主题中為require_once指定路徑?wordpressphpwordpressthemedevelopmentwordpresschildtheme2020-07-19 15:25
如果您設置為靜態首頁,為什麼会有分頁?
在首頁上使用分頁的帖子網格的正確方法是將首頁設置為"您的最新帖子".然後,您將開發自己的
front-page.php
,威兹威兹 或home.php
模板以將帖子顯示為網格(使用模板層次結構確定所需的檔案)。在该模板中,您不需要使用
index.php
或WP_Query
或類似的东西.只有主迴圈:請註意我所做的其他更改:
威兹威兹 威兹威兹 迴圈。我删除了引數
<h2>Recent Posts</h2> <div class="grid row posts"> <?php while ( have_posts() ) : the_post(); ?> <div class="col"> <!-- Post markup goes here. --> </div> <?php endwhile; ?> </div> <div class="pagination"> <?php echo paginate_links( array( 'end_size' => 2, 'mid_size' => 1, 'prev_text' => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ), 'next_text' => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ), ) ); ?> </div>
因為它们由於適当的迴圈結構而不必要,或者只是將它们設置為預設值。如果您在評論中让我感到幽默,那麼這種對
The pagination links should be outside the 的滥用 分頁是我在這个網站上看到的最常见的錯誤,所以我很好奇您从何而来? ,因為對於任何標準模板中的主帖子列表而言,它永远都没有必要,但是我几乎每天都看到它.有没有相關的教程来推廣此內容,或者在官方文件中暗示了此內容?
while