問題描述
例如,我在我的網站上有一個連結,如/標籤/綠色,並從所有帖子中選擇內容標記為綠色的檔案顯示使用檔案 loop-tag.php,這是簡單的
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Here I grab the image from the post with that tag -->
<?php endwhile; ?>
然而,這項工作僅限於 10 個職位。為什麼這樣限制在 10?
最佳解決方案
因為它必須設定在您的 wordpress 站點的後端。您可以從 Blog pages show at most 欄位檢查並將其更改為 settings => 閱讀頁面選單。如下圖所示。
它將更改所有頁面的設定,但如果要僅對標籤頁進行此更改,則在您的情況下,您可以更改 loop-tag.php 檔案中的程式碼如下:
global $wp;
$s_array = array('posts_per_page' => -1); // Change to how many posts you want to display
$new_query = array_merge( $s_array, (array)$wp->query_vars );
query_posts($new_query);
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Here I grab the image from the post with that tag -->
<?php endwhile; ?>
<?php wp_reset_query();?>
您也可以使用 pre_get_posts 動作鉤來更改帖子限制。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。
