【问题标题】:How to place a div below header/navigation bar in wordpress?如何在wordpress的标题/导航栏下方放置一个div?
【发布时间】:2012-03-13 15:05:51
【问题描述】:

我想在导航栏下方放置一个div div 的宽度必须与wordpress 主题的宽度相同。此 div 位于帖子和 侧边栏 上方,就像放置在导航栏下方的广告一样。

我试过get_headerloop_startget_header 将 div 置于顶部,甚至在 站点名称 打印之前。 loop_start 虽然将其打印在导航栏下方,但与 侧边栏重叠

是否有任何独立于主题的 wordpress api (tag) 可以用来实现这一点?

我知道可以编辑主题文件,但这意味着编辑我安装的所有主题。所以我不想这样做。

我想在 多站点安装中执行此操作。

谢谢你..

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    你可以使用add_action(loop_start,smtg)add_action(loop_end,smtg)apply_filters('the_content', $content);

    喜欢:

    <?php
    $content = apply_filters('the_content', $content);
    $content = do_your_stuff;
    ?>
    

    这真的取决于你想做什么...... 在这里查看更多:http://codex.wordpress.org/Plugin_API/Action_Reference

    所有“上 - 下 - 重叠”都不是真正相关的 - 它们是特定于 CSS 的.. 但是,如果您真的想这样做 - 您可以随时在内容上使用 REGEX...

    或其他方法 - 例如:

    function k99_replace_content(){
    
    //get the content   
    $content= get_the_content(); //get the content as a variable
    
    // where we want to cut ??
    // by length ??
    $full_length= STRLEN($content);
    $cutting_point = ($full_length/ 2);
    // regex ??
    //do regex stuff here ..
    
    // clip off the first part - if we choose by length
    $firstpart = SUBSTR($content, 0, $cutting_point);
    
    //  ending '<br>' 
    $end_point = STRRPOS($firstpart, '<br>');
    
    // add whatever
    
    return SUBSTR($content, 0, $end_point) . "<div>put whatever you want>/div>" . SUBSTR($content, $end_point); 
    }
    

    add_filter('the_content', 'k99_replace_content');

    或最后一个选项,使用@IanB 建议的方法和其中一种方法 - 并通过过滤器包含..

    【讨论】:

      【解决方案2】:

      使用您的 div html 信息创建一个文件,将其保存为 div_template.php 并通过 ftp 上传到您的主题文件。

      然后,将此代码放在导航条码下方:

      <?php include('div_template.php'); ?>
      

      这将动态添加您的 div html 代码,无论您想放在哪里。

      试试看!

      【讨论】:

      • 我知道这肯定会工作...但我不想编辑主题文件...对于多站点,我必须为每个主题安装都这样做...这就是为什么我正在尝试开发插件...我想要一个独立于主题的解决方案...
      【解决方案3】:

      回答我自己的问题...

      函数get_header()wp-includes/general-template.php中定义。放置
      echo '&lt;div&gt; My content &lt;/div&gt;';或在他的@中提到的@IanB 987654321@, &lt;?php include 'div_template.php'; ?&gt; 在这个函数定义的最后解决了我的问题。

      修改这个功能有一个优点和一个缺点... 优点是每个主题都不需要调整来实现这是因为get_headers() 是独立于主题的,缺点是我们所做的这个修改,会在 wordpress 更新到新版本时被删除。

      仍然感谢所有回复...

      和平...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 2019-07-07
        • 2017-12-15
        • 2019-12-03
        相关资源
        最近更新 更多