<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                functions.php文件是您向WordPress主題添加獨特功能的地方。 它可以用于掛接WordPress的核心功能,使您的主題更具模塊化,可擴展性和功能性。 ## 什么是functions.php? functions.php文件的行為就像一個WordPress插件,向WordPress網站添加功能和功能。 您可以使用它來調用WordPress函數并定義自己的功能。 >[warning] 注意:使用插件或functions.php可以生成相同的結果。 如果您正在創建應該可用的新功能,無論網站如何,最好將其放入插件。 使用WordPress插件或使用functions.php有優勢和折衷。 WordPress插件: - 需要具體的,唯一的標題文字; - 存儲在wp-content/plugins中,通常在子目錄中; - 激活時僅在頁面加載時執行; - 適用于所有主題; 并且應該有一個目的 - 例如,提供搜索引擎優化功能或幫助備份。 同時,一個functions.php文件: - 不需要唯一的標題文字; - 存儲在wp-content/themes中的主題的子目錄中; - 僅在活動主題的目錄中執行; - 僅適用于該主題(如果主題已更改,則不再使用該功能); 并且可以有許多代碼塊用于許多不同的目的。 - 每個主題都有自己的函數文件,但只有活動主題的functions.php中的代碼才能實際運行。 如果你的主題已經有一個功能文件,你可以添加代碼。 如果沒有,您可以創建一個名為functions.php的純文本文件,以添加到您的主題目錄中,如下所述。 子主題可以有自己的functions.php文件。 將函數添加到子函數文件是修改父主題的無風險方式。 這樣,當父主題更新時,您不必擔心新添加的功能會消失。 >[warning] 注意:雖然子主題的functions.php是在父主題的functions.php之前由WordPress加載的,但它不會覆蓋它。 子主題的functions.php可用于增加或替換父主題的功能。 同樣,在加載任何插件文件之后,會加載functions.php。 使用functions.php可以: - 使用WordPress掛鉤。 例如,使用excerpt_length過濾器,您可以更改您的職位摘錄長度(默認為55個字)。 - 使用add_theme_support()啟用WordPress功能。 例如,打開帖子縮略圖,帖子格式和導航菜單。 - 定義要在多個主題模板文件中重用的功能。 >[warning] 警告:如果WordPress插件調用相同的功能或過濾器,就像您在functions.php中所做的那樣,結果可能是意外的,甚至導致您的站點被禁用。 ## 示例 以下是您可以在functions.php文件中使用的一些示例,以支持各種功能。 如果您選擇將其提交到WordPress.org主題目錄,則這些示例中的每一個都可以在您的主題中使用。 ### 主題設置 一些主題功能應該包含在一個“設置”功能中,最初在您的主題被激活時運行。 如下圖所示,這些功能可以添加到您的functions.php文件中,以激活推薦的WordPress功能。 >[warning] 注意:用你的主題名命名你的函數很重要。 以下所有示例都使用myfirsttheme_作為其命名空間,它們應根據您的主題名稱進行自定義。 要創建此初始函數,請啟動一個名為myfirsttheme_setup()的新函數,如下所示: ``` if ( ! function_exists( 'myfirsttheme_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features * * It is important to set up these functions before the init hook so that none of these * features are lost. * * @since MyFirstTheme 1.0 */ function myfirsttheme_setup() { ``` >[warning] 注意:在上面的例子中,函數myfirsttheme_setup啟動但未關閉。 確保關閉您的功能 ### automatic-feed-links 默認情況下,自動Feed鏈接可以發布和評論RSS Feed。 這些Feed將自動顯示在<head>中。 可以使用add_theme_support()調用它們。 ``` add_theme_support( 'automatic-feed-links' ); ``` ### 導航菜單 自定義導航菜單允許用戶在“菜單”管理面板中編輯和自定義菜單,為用戶提供了一個拖放界面來編輯其主題中的各種菜單。 您可以在functions.php中設置多個菜單。 可以使用register_nav_menus()添加它們,并使用wp_nav_menu()插入主題,如本手冊后面所述。 如果您的主題將允許多個菜單,則應使用數組。 雖然某些主題將不具有自定義導航菜單,但建議您允許此功能輕松進行自定義。 ``` register_nav_menus( array( 'primary' => __( 'Primary Menu', 'myfirsttheme' ), 'secondary' => __( 'Secondary Menu', 'myfirsttheme' ) ) ); ``` 您可以稍后使用wp_nav_menu()并使用分配的名稱(即主)將其定義的每個菜單作為theme_location參數。 ### 加載文本域 通過使您的主題中的字符串可用于翻譯,主題可以翻譯成多種語言。 為此,您必須使用load_theme_textdomain()。 有關使您的主題可用于翻譯的更多信息,請閱讀[國際化](themes/internationalization.md)部分。 ``` load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' ); ``` ### 發布縮略圖 發布縮略圖和精選圖片可讓您的用戶選擇一個圖片來表示他們的帖子。 您的主題可以根據其設計決定如何顯示它們。 例如,您可以選擇在歸檔視圖中顯示每個帖子的帖子縮略圖。 或者,您可能希望在主頁上使用大型特色圖片。 雖然不是每個主題都需要特色圖片,但建議您支持發布縮略圖和精選圖片。 ``` add_theme_support( 'post-thumbnails' ); ``` ### 發布格式 發布格式允許用戶以不同的方式格式化其帖子。 這對于允許博主根據帖子的內容選擇不同的格式和模板非常有用。 add_theme_support()也用于Post格式。 這是推薦的。 ``` add_theme_support( 'post-formats', array ( 'aside', 'gallery', 'quote', 'image', 'video' ) ); ``` 進一步了解[發布格式](themes/post-formats.md)。 ### 初始設置示例 包括所有上述功能將給你一個如下所示的functions.php文件。 添加了代碼注釋以便將來的清晰度。 如本示例底部所示,您必須添加所需的add_action()語句以確保myfirsttheme_setup函數已加載。 ``` if ( ! function_exists( 'myfirsttheme_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which runs * before the init hook. The init hook is too late for some features, such as indicating * support post thumbnails. */ function myfirsttheme_setup() { /** * Make theme available for translation. * Translations can be placed in the /languages/ directory. */ load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' ); /** * Add default posts and comments RSS feed links to <head>. */ add_theme_support( 'automatic-feed-links' ); /** * Enable support for post thumbnails and featured images. */ add_theme_support( 'post-thumbnails' ); /** * Add support for two custom navigation menus. */ register_nav_menus( array( 'primary' => __( 'Primary Menu', 'myfirsttheme' ), 'secondary' => __('Secondary Menu', 'myfirsttheme' ) ) ); /** * Enable support for the following post formats: * aside, gallery, quote, image, and video */ add_theme_support( 'post-formats', array ( 'aside', 'gallery', 'quote', 'image', 'video' ) ); } endif; // myfirsttheme_setup add_action( 'after_setup_theme', 'myfirsttheme_setup' ); ``` ## 內容寬度 內容寬度添加到您的functions.php文件中,以確保沒有內容或資源破壞站點的容器。 內容寬度為添加到您的網站的任何內容(包括已上傳的圖像)設置允許的最大寬度。 在下面的示例中,內容區域的最大寬度為800像素。 沒有內容會比這更大。 ``` if ( ! isset ( $content_width) ) $content_width = 800; ``` ## 其他特性 還有其他常見功能可以在functions.php中包含。 下面列出了一些最常見的功能。 點擊并了解有關這些功能的更多信息。 (根據新頁面展開此部分。) - [自定義Headers](themes/custom-headers.md) - [Sidebars(Widgets)](themes/sidebars.md) - 自定義背景 - 添加編輯器樣式 - HTML5 - 標題標簽 ## 你的functions.php文件 如果您選擇包括上面列出的所有功能,這是您的functions.php可能是什么樣子。 已經參考上面的評論。 ``` /** * MyFirstTheme's functions and definitions * * @package MyFirstTheme * @since MyFirstTheme 1.0 */ /** * First, let's set the maximum content width based on the theme's design and stylesheet. * This will limit the width of all uploaded images and embeds. */ if ( ! isset( $content_width ) ) $content_width = 800; /* pixels */ if ( ! function_exists( 'myfirsttheme_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which runs * before the init hook. The init hook is too late for some features, such as indicating * support post thumbnails. */ function myfirsttheme_setup() { /** * Make theme available for translation. * Translations can be placed in the /languages/ directory. */ load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' ); /** * Add default posts and comments RSS feed links to <head>. */ add_theme_support( 'automatic-feed-links' ); /** * Enable support for post thumbnails and featured images. */ add_theme_support( 'post-thumbnails' ); /** * Add support for two custom navigation menus. */ register_nav_menus( array( 'primary' => __( 'Primary Menu', 'myfirsttheme' ), 'secondary' => __('Secondary Menu', 'myfirsttheme' ) ) ); /** * Enable support for the following post formats: * aside, gallery, quote, image, and video */ add_theme_support( 'post-formats', array ( 'aside', 'gallery', 'quote', 'image', 'video' ) ); } endif; // myfirsttheme_setup add_action( 'after_setup_theme', 'myfirsttheme_setup' ); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看