logo
  • 教程列表
  • SO官方文檔
  • 交替主迴圈(預獲取過濾器)
    • 更改主迴圈的每頁帖子
    • 甚至更具體的迴圈定位
    • 僅顯示一個類別的帖子
    • 預獲取帖子過濾基本用法
    • 從帖子列表編輯共享中排除類別
    • 僅針對主要的 WordPress 迴圈
  1. StackOverflow 文件
  2. WordPress 教程
  3. 交替主迴圈(預獲取過濾器)

交替主迴圈(預獲取過濾器)

Created: November-22, 2018

如果你使用的是 PHP 5.3.0 或更高版本,則可以使用閉包( 匿名函式 )

add_action( 'pre_get_posts', function( $query ) {
    if( !$query->is_main_query() || is_admin() ) return;

    // this code will run only if
    // - this query is main query
    // - and this is not admin screen
});
  • 更改主迴圈的每頁帖子

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明