2013-10-05 41 views
1

這可能是一個奇怪的問題。當我添加像Facebook Like Button和Gigpress這樣的插件時,他們提供了在每個單頁博客文章之前或之後插入內容的選項。例如,我將Gigpress和FB Like按鈕設置爲在我的帖子中的文本下方添加內容,這是行得通的,如果不完美的話。類似按鈕顯示在帖子文本下方。wordpress插件如何添加內容?

那麼在後端如何實現呢?它看起來並不像模板或其他php文件被插件所改變,但似乎也沒有任何明顯的PHP代碼將拉動數據。這種類型的功能以某種方式構建到「框架」中?

我問的原因是格式化的原因......由兩個插件添加的內容衝突,看起來不好。我想弄清楚如何修改CSS。

感謝

回答

3

它們與FiltersActions實現它,並掛接到他們。

在你的情況 - 與the_content過濾器..

例(法典):

add_filter('the_content', 'my_the_content_filter', 20); 
/** 
* Add a icon to the beginning of every post page. 
* 
* @uses is_single() 
*/ 
function my_the_content_filter($content) { 

    if (is_single()) 
     // Add image to the beginning of each page 
     $content = sprintf(
      '<img class="post-icon" src="%s/images/post_icon.png" alt="Post icon" title=""/>%s', 
      get_bloginfo('stylesheet_directory'), 
      $content 
     ); 

    // Returns the content. 
    return $content; 
} 

一個更簡單的理解的例子:

add_filter('the_content', 'add_something_to_content_filter', 20); 


function add_something_to_content_filter($content) { 

      $original_content = $content ; // preserve the original ... 
      $add_before_content = ' This will be added before the content.. ' ; 
      $add_after_content = ' This will be added after the content.. ' ; 
      $content = $add_pre_content . $original_content . $add_sur_content ; 

     // Returns the content. 
     return $content; 
    } 

在行動中看到這個例子中,把它放在你的functions.php

這實際上是理解wordpress最重要的一步,並開始編寫插件。如果您真的有興趣,請閱讀上面的鏈接。

此外,打開你剛纔提到的插件文件並查找 FiltersActions ...

+0

好感謝!對wordpress來說很新,所以我是一個建立插件的途徑,但這非常有幫助!你搖滾。 –

+0

好。祝你編寫插件。如果答案有幫助,請嘗試接受它。 (得分之下的小綠色「v」) –