2013-02-20 14 views
1

快速的问题将内容添加到WordPress的the_content():如何使用钩

可以说这是我的内容股利:

<div id="content"> 
    <ul id="featured-controllers" class="clearfix"> 
     <li class="first" style="min-height: 182.167px;"> 
      <div class="et_slide_hover" style="opacity: 0; display: block;"></div> 
      <div class="controller"> 
      <h2>Volunteers have more fun</h2> 
      </div> 
      <div class="et_animated_bar" style="display: block; width: 238.055px; left: 0.488656px; overflow: hidden;"></div> 
     </li> 
     <li style="min-height: 182.167px;" class=""> 
      <div class="et_slide_hover" style="display: block; opacity: 0;"></div> 
      <div class="controller"> 
       <h2>Mark your calendar</h2> 
       Check out our schedule of upcoming events...</p> 
      </div> 
     <div class="et_animated_bar" style="display: none; width: 239px; left: 0px;"> </div> 
    </li> 
    </ul> 
    <div id="services" class="clearfix"> 
     <div class="service"> 
      <h3>Sample Page</h3> 
      <p> 
      <a href="http://collaborativecommunityprogram.org/wp-content/uploads/sample.png"> 
      <img class="alignnone size-medium wp-image-12" width="300" height="84" src="http://collaborativecommunityprogram.org/wp-content/uploads/sample-300x84.png" alt="sample"> 
      </a> 
      </p> 
     </div> 
    </div> 
    <div id="footer"> 
     <div id="footer-widgets" class="clearfix"> 
      <div class="footer-widget" style="min-height: 58px;"> 
       <div id="text-2" class="f_widget widget_text"> 
        <h4 class="widgettitle"> </h4> 
       <div class="textwidget"> 
      <img src="http://collaborativecommunityprogram.org/wp-content/uploads/footer-social.png"> 
       </div> 
     </div> 
    </div> 
</div> 

格式化有点搞砸了,但我想将内容添加到位于上述内容div内的div 元素的顶部的具有“featured-controllers”的id的 ul列表。我正在尝试追加内容。

这里是网站:http://collaborativecommunityprogram.org/

现在,我试着这样做:

function pc_custom_content($content) { 
    return $content."<div><p>This is a test</p></div>"; 
} 
add_filter('the_content', 'pc_custom_content'); 

但其追加这个div到DIV与“服务”,而不是 的ID结束位于顶部的“featured-controllers”的ID。

有没有什么办法可以将一些自定义内容粘贴到“featured-controllers”列表的ul id中?我发现没有办法通过管理面板来做到这一点。

任何帮助,非常感谢。

谢谢!

+0

3日到最后行 - 成什么样? – 2013-02-20 03:55:53

+0

我很抱歉,我不得不做一些修改:P – 2013-02-20 03:58:53

+0

您正在寻找的可能是一个简码。你想把这个内容添加到所有页面吗? – 2013-02-20 04:00:08

回答

1

您可以从管理面板添加短代码到您的内容。然后从您的functions.php或插件调用您的php代码。

Wordpress Codex

//you can pass arguments to shortcodes and they are stored in the $atts array 
function function_name($atts){ 
    return "dynamic content to replace shortcode with"; 
} 
add_shortcode('shortcode_name', 'function_name'); 

修改,随后这在您想要的动态内容出现在WP管理员添加到您的主页的内容:

[shortcode_name] 
+0

嘿尼古拉斯,谢谢你的回答! – 2013-02-20 04:16:51

+0

我正在研究短代码(不熟悉),唯一的问题是,我无法进入管理 - >页面中的“主页”页面以弹出该简码。试图弄清楚如何将它放在那里 – 2013-02-20 04:17:57

+0

@ AlexDouglas啊,您可能必须在Settings-> Reading中将您的主页默认设置更改为现有页面。如果您希望将主页保留为发布列表,则可以将动态内容代码直接添加到主页的模板中。如果您不确定哪个模板是您的主页,请使用以下内容:[Template Hierarcy](http://codex.wordpress.org/images/1/18/Template_Hierarchy.png) – 2013-02-20 04:24:42