2013-10-05 40 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”) –