当前位置: 首页>编程笔记>正文

wordpress底部菜單插件,sysbios掛鉤函數使用_使用動作掛鉤自定義WordPress主題

wordpress底部菜單插件,sysbios掛鉤函數使用_使用動作掛鉤自定義WordPress主題

sysbios掛鉤函數使用

Your WordPress theme is one of the main core components that defines the look and feel of your website.

WordPress主題是定義網站外觀的主要核心組件之一。

wordpress底部菜單插件,While WordPress theme development has become a popular and profitable business for some developers and designers, all developers working with WordPress should know how to customize – if not construct – a quality theme.

盡管WordPress主題開發已成為一些開發人員和設計師的流行且盈利的業務,??但所有使用WordPress的開發人員都應該知道如何自定義(即使不是構建)高質量的主題。

Professional premium themes in popular marketplaces contain dozens of in-built features and components to define the presentation and functionality of WordPress websites. Nevertheless, we need to be able to make the themes extendable and customizable, allowing their users to stand out from the rest and to meet specific needs.

流行市場中的專業高級主題包含數十個內置功能部件,用于定義WordPress網站的表示形式和功能。 但是,我們需要能夠使主題具有可擴展性和可定制性,以使他們的用戶脫穎而出并滿足特定需求。

sysbios串口中斷、WordPress action hooks provide an excellent way to extend WordPress themes. In this tutorial, we’re going to look at how we can effectively use these action hooks. Here I am assuming that you have some basic knowledge of using WordPress action hooks.

WordPress動作掛鉤提供了擴展WordPress主題的絕佳方法。 在本教程中,我們將研究如何有效使用這些動作掛鉤。 在這里,我假設您具有使用WordPress操作掛鉤的一些基本知識。

動作掛鉤的作用 (The Role of Action Hooks)

Themes are built by designers of developers based on their imagination. You may think you have the capabilities to design the “perfect theme” with all the necessary features. But still there will be people who want your theme to have certain modifications to the design, before being willing to use it on their own websites.

主題是由開發人員的設計師根據其想象力構建的。 您可能會認為您具有設計具有所有必要功能的“完美主題”的能力。 但是仍然有些人希望您的主題在不愿意在自己的網站上使用之前對其設計進行某些修改。

bios中斷使用,Here is a screenshot of my favorite WordPress theme called Avada.

這是我最喜歡的WordPress主題Avada的屏幕截圖。

Avada theme screenshot

I like most things in the features and design, but I don’t like the social menu (highlighted). I’d prefer to use my own design for this section. Similarly, each user may have their own requirements.

我喜歡功能和設計中的大多數內容,但不喜歡社交菜單(突出顯示)。 我更愿意在本節中使用自己的設計。 同樣,每個用戶可能都有自己的要求。

bios中斷大全、No WordPress developer can satisfy everyone with any one theme design. But we can extend and adapt themes, so that anyone can have a unique design built with components on top of the basic design and features.

沒有WordPress開發人員可以通過任何一種主題設計使所有人滿意。 但是我們可以擴展和調整主題,以便任何人都可以擁有在基本設計和功能之上構建具有組件的獨特設計。

WordPress action hooks simplify this process. With action hooks, we can remove existing components or add new components as necessary. Anyone who is experienced in WordPress development can then easily customize the existing features by modifying the theme code or adding custom codes through plugins.

WordPress動作掛鉤可簡化此過程。 使用動作掛鉤,我們可以刪除現有組件或根據需要添加新組件。 然后,任何具有WordPress開發經驗的人都可以通過修改主題代碼或通過插件添加自定義代碼來輕松自定義現有功能。

基本動作掛鉤 (Essential Action Hooks)

wordpress小工具插件、We have the choice of deciding whether to go with action hooks or not. There are three action hooks that are built into almost all WordPress themes. Any theme would be considerably limited without these hooks:

我們可以選擇是否使用動作掛鉤。 幾乎所有WordPress主題都內置了三個動作掛鉤。 沒有這些鉤子,任何主題都會受到很大的限制:

  • wp_head

    wp_head

sysbios在ram調試、Included in the head section of the theme for plugin developers to add their own scripts, styles and necessary information. Calling the wp_head function in your theme header, will call the do_action function inside the core code.

包含在主題的頭部,供插件開發人員添加自己的腳本,樣式和必要的信息。 調用wp_head在主題頭功能,將調用do_action核心代碼中的功能。

  • wp_footer

    wp_footer

bios中斷手冊?Included just before the closing body tag of the HTML document, for plugin developers to add scripts, styles and necessary display information. wp_footer works in a similar way to the wp_head function and calls the do_action function inside the core files.

緊接在HTML文檔的body標記之前,供插件開發人員添加腳本,樣式和必要的顯示信息。 wp_footer工作方式與wp_head函數類似,并在核心文件中調用do_action函數。

  • comment_form

    comment_form

Used to modify the design and fields of existing comment form for posts and pages.

用于修改帖子和頁面的現有評論表單的設計和字段。

開發自定義動作掛鉤 (Developing Custom Action Hooks)

Now it’s time to develop our own custom hooks specific to themes. The real power of hooks comes with this method as we can define any number of custom hooks anywhere in the theme.

現在是時候開發針對主題的自定義掛鉤了。 鉤子的真正功能在于此方法,因為我們可以在主題中的任何位置定義任意數量的自定義鉤子。

First let’s consider the following code which creates a custom action hook for our themes.

首先,讓我們考慮以下代碼,這些代碼為主題創建了自定義動作掛鉤。

function wpr_after_post_title() {echo "<img src='promotion-image.jpg' />";}add_action('wpr_after_post_title','wpr_after_post_title');

These days, many websites offering a product or services have a blog or articles section to attract readers and market their products. So they produce articles about information related to the product. The goal is to market the products through the blog. Often, we see?advertisements or promotion placed just after the post title. In such scenarios we can use the preceding code to implement the feature.

如今,許多提供產品或服務的網站都有博客或文章部分,以吸引讀者并銷售他們的產品。 因此,他們制作了有關產品信息的文章。 目標是通過博客營銷產品。 通常,我們會在帖子標題之后看到廣告或促銷。 在這種情況下,我們可以使用前面的代碼來實現該功能。

add_action function takes a custom action name and function name unique to the application. Then we can add the do_action in the theme after the title of the post to display the promotion banner as shown in the following code.

add_action函數采用自定義操作名稱和應用程序唯一的功能名稱。 然后,我們可以在帖子標題之后的主題中添加do_action ,以顯示促銷標語,如以下代碼所示。

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2><?php do_action('wpr_after_post_title'); ?>

Having action hooks in important positions like this allows plugin developers to quickly add custom features without digging into the core theme code.

這樣在重要位置放置動作掛鉤,可使插件開發人員快速添加自定義功能,而無需深入研究核心主題代碼。

單個動作掛鉤的多次執行 (Multiple Execution of Single Action Hooks)

Once you define custom action hooks and make it public, any developer can implement them using various plugins. In situations where two or more developers implement the same hook in their plugins, precedence of the actions becomes a concern.

定義自定義動作掛鉤并將其公開后,任何開發人員都可以使用各種插件來實現它們。 在兩個或多個開發人員在其插件中實現相同的掛鉤的情況下,操作的優先級成為一個問題。

Consider the following code where two plugins implement the same action.

考慮以下代碼,其中兩個插件實現相同的操作。

<?phpfunction wpr1_after_post_title() {// Plugin 1}add_action('wpr_after_post_title','wpr1_after_post_title');function wpr2_after_post_title() {// Plugin 2}add_action('wpr_after_post_title','wpr2_after_post_title');?>

In this scenario, which action executes first depends on the plugin name and how the plugin is positioned in the active_plugins field in wp_options table. Let’s say we want to display the output of Plugin 2 before the output of Plugin 1. We won’t be able to get it work with the above technique since Plugin 1 is located first in the active_plugins field.

在這種情況下,首先執行哪個操作取決于插件名稱以及插件在wp_options表的active_plugins字段中的wp_options 。 假設我們要在插件1的輸出之前顯示插件2的輸出。由于插件1首先位于active_plugins字段中,因此無法通過上述技術使用它。

The priority parameter of action hooks becomes useful at this point. We can pass a numeric value as a third parameter to define the execution priority of the action hooks. Let’s consider the preceding example with priority values.

此時,動作掛鉤的優先級參數變得很有用。 我們可以傳遞一個數字值作為第三個參數來定義動作掛鉤的執行優先級。 讓我們考慮具有優先級值的上述示例。

function wpr1_after_post_title() {// Plugin 1}add_action('wpr_after_post_title','wpr1_after_post_title',50);function wpr2_after_post_title() {// Plugin 2}add_action('wpr_after_post_title','wpr2_after_post_title',40);

Now you will be able to see the execution of Plugin 2 function before the Plugin 1 function based on the priority level given. As value gets higher, priority will get lower and hence will execute further down the page.

現在,基于給定的優先級,您將能夠在Plugin 1功能之前看到Plugin 2功能的執行情況。 隨著值的增加,優先級將降低,因此將在頁面的下方執行。

So it’s better to define your action hooks with priority values so that precedence of other actions can be adjusted according to the required positioning.

因此,最好使用優先級值定義動作掛鉤,以便可以根據所需位置調整其他動作的優先級。

如何將可插入動作掛鉤添加到主題? (How to Add Pluggable Action Hooks to Themes?)

WordPress action hooks implementation consists of two parts. First we define an action hook using add_action function. Then we execute the action hook using do_action. As theme developers, your responsibility is to execute action hook when necessary. Defining and implementing the action needs to be done by plugin developers. So whenever you want to use an action hook, just place the following code in necessary locations.

WordPress動作掛鉤實現由兩部分組成。 首先,我們使用add_action函數定義一個動作掛鉤。 然后,我們使用do_action執行動作掛鉤。 作為主題開發人員,您的責任是在必要時執行動作掛鉤。 定義和實施該操作需要由插件開發人員完成。 因此,每當要使用動作掛鉤時,只需將以下代碼放在必要的位置。

<?php do_action("action hook name"); ?>

Proving action hooks makes it easy for plugin developers to add new sections and content for the theme layout. But what if someone wants to change existing section?

驗證動作掛鉤使插件開發人員可以輕松地為主題布局添加新的部分和內容。 但是,如果有人要更改現有部分怎么辦?

Consider the following layout.

考慮以下布局。

dummy layout screenshot

This screen shows the blog post design of a WordPress theme. You can see the post date and author under the title. Also the category and tags are placed at the end. Let’s say you don’t like the design of these components and want to design your own.

此屏幕顯示WordPress主題的博客文章設計。 您可以在標題下看到發布日期和作者。 類別和標簽也放置在末尾。 假設您不喜歡這些組件的設計,而是想要設計自己的組件。

If those sections are directly inserted into the theme, it’s difficult for plugin developers to change the design without modifying the core theme code. Let’s see how we can provide a solution with action hooks.

如果將這些部分直接插入主題中,那么插件開發人員很難在不修改核心主題代碼的情況下更改設計。 讓我們看看如何為操作鉤提供解決方案。

<?php// Post title codedo_action("post_date_and_author");// Post contentdo_action("post_category");do_action("post_tags");?>

All the sections are defined as action hooks instead of directly embedding into HTML document. The following code implements the post_date_and_author action inside the theme functions file.

所有部分都定義為動作掛鉤,而不是直接嵌入HTML文檔中。 以下代碼在主題函數文件中實現了post_date_and_author操作。

<?phpfunction post_date_and_author(){echo "Date area related HTML code";}add_action('post_date_and_author','post_date_and_author');?>

Now you have can replace existing design components as well as add new components to the theme. Following is the implementation for the preceding scenario inside a?custom plugin.

現在,您可以替換現有的設計組件,也可以向主題添加新的組件。 以下是自定義插件中上述場景的實現。

<?phpfunction wpr_post_date_and_author(){echo "New design for date section by the plugin";}add_action('post_date_and_author','wpr_post_date_and_author');function wpr_remove_custom_actions() {remove_action('post_date_and_author','post_date_and_author');}add_action('init','wpr_remove_custom_actions');?>

Here, the developer has provided their own design for the date and author section. The original post_date_and_author hook defined by the theme will be removed on init action.

在這里,開發人員為日期和作者部分提供了自己的設計。 主題定義的原始post_date_and_author掛鉤將在init操作時刪除。

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure. – WordPress Codex

重要: 要刪除一個鉤子,添加鉤子時, $function_to_remove$priority參數必須匹配。 這適用于過濾器和操作。 如果移除失敗,將不會發出警告。 – WordPress Codex

Then we add the same action with plugin specific functions to modify the date section design.

然后,我們使用插件特定的功能添加相同的操作,以修改日期部分的設計。

The following screen previews how the previous layout can be changed to provide a different design.

以下屏幕預覽了如何更改先前的布局以提供不同的設計。

revised dummy layout screenshot

記錄可插拔動作掛鉤 (Documenting Pluggable Action Hooks)

You can add any number of action hooks add features to make your theme highly customizable. Plugin developers are not aware of the available theme hooks, unless they explore the source codes to find them. Therefore it’s ideal to document the available action hooks of your theme.

您可以添加任意數量的動作掛鉤添加功能,以使您的主題高度可定制。 插件開發人員不了解可用的主題掛鉤,除非他們探索源代碼以找到它們。 因此,最好記錄主題可用的動作掛鉤。

One way of using action hooks is?to add scripts, styles and similar contents which work internally without displaying anything on the browser.?Another way is to directly modify the page layout to add design components or remove existing components.

使用動作掛鉤的一種方法是添加腳本,樣式和類似內容,這些腳本,樣式和類似內容在內部運行而不會在瀏覽器上顯示任何內容。 另一種方法是直接修改頁面布局以添加設計組件或刪除現有組件。

If you do go with action hooks, your documentation needs to include the details such as the positioning of the action hook in the template, preferred parameters, dimensions of the content and types of design components preferred in the given locations.

如果確實要使用動作掛鉤,則文檔需要包括詳細信息,例如動作掛鉤在模板中的位置,首選參數,內容的尺寸以及在給定位置首選的設計組件的類型。

It’s up to you to decide the places to apply action hooks in your themes. I would use action hooks in the following sections:

由您決定在主題中應用動作掛鉤的位置。 我將在以下部分中使用動作掛鉤:

  • After the main menu

    主菜單后
  • After the post or page content

    帖子或頁面內容之后
  • Before and after the post title

    帖子標題前后
  • Before footer section

    頁腳前部分
  • Before and after sidebar widgets

    側邊欄小部件之前和之后

Now it’s time to help each other by sharing our experiences. Feel free to add your suggestions on action hooks and how you use them effectively in your WordPress themes.

現在是時候通過分享我們的經驗互相幫助。 隨意添加有關動作掛鉤的建議以及如何在WordPress主題中有效使用它們。

Looking forward to hearing from you.

期待您的回音。

翻譯自: https://www.sitepoint.com/customizing-wordpress-themes-with-action-hooks/

sysbios掛鉤函數使用

https://www.nshth.com/bcbj/326368.html
>

相关文章:

  • wordpress底部菜單插件
  • sysbios串口中斷
  • bios中斷使用
  • bios中斷大全
  • wordpress小工具插件
  • sysbios在ram調試
  • bios中斷手冊
  • bios是調試模式嗎
  • pdf翻譯網站,1 Trillion Dollar Refund – How To Spoof PDF Signatures——欺騙PDF簽名
  • 如何創建一個抽象類,創建具體的產品,并繼承產品抽象類
  • 主從庫理論知識-主從同步如何實現?
  • Tomcat環境變量配置,Mybatis的配置文件參數詳解
  • I Am You,POJ 3130 How I Mathematician Wonder What You Are! 半平面交
  • 要學vue需要學什么基礎知識,第一章 Vue基礎入門
  • win7下安裝win10,win10下安裝Ubuntu18.10雙系統
  • vmplayer怎么使用烏邦圖,烏邦圖環境安裝
  • 計算機專業要不要考研——寫的很棒
  • redisson看門狗原理,記錄一次redis漏洞攻擊
  • 任意波形發生器,基于單片機信號波形發生器系統設計-畢設課設
  • 嵌入式驅動,嵌入式Linux驅動大全問世,十年磨一劍,視頻!服務!新老客戶都有大折扣!
  • socket連接器v2下載,Netty(一)基礎socketchannel,Buffer,selector黏包 半包解決 實戰
  • 大一c語言程序設計筆記,吉林大學2013級大一下學期程序設計作業:同學通訊錄系統
  • 暑期小學生計算機培訓班,青島小學生學習編程暑假
  • 熊貓毛小喵喵去哪里了,小西貝、何小喵看熊貓之觀察者設計模式
  • 如何用c語言比較兩個數的大小,如何用C語言求兩個數的較大值
  • 輾轉相除法求最小公倍數的方法,更相減損術--最大公約數
  • 輾轉相除法求最小公倍數的方法,如何求出兩個整數的最大公約數
  • 李新義的書畫藝術,中國現代書畫家——譚奇中、李義象、高俊鵬等
  • 海底撈張勇名言,致張勇先生一封信:海底撈的“七宗罪”!
  • WPF學習(12)動畫
  • ui自動化測試工具,移動端UI自動化之appium的使用(二)
  • 爬蟲網站,Search For Free —— 新聞爬蟲及爬取結果的查詢網站
  • tenda騰達無線設置,騰達F6路由器無線中繼功能設置
  • 斐波那契數列、小青蛙跳臺階
  • OJ每日一練——小青蛙上臺階
  • 小青蛙貝葉斯
  • 小青蛙走臺階問題
  • MySQL數據庫下載,NAVICAT FOR MYSQL存儲過程