doujiang1939 2015-03-06 14:32
浏览 55
已采纳

在自定义div中包装wordpress帖子和标题

I'm trying to prepare a blog for microformat, so I need a div to start above the title and close just above the social share buttons (and below meta data, date, author, # of views, etc) - see site for reference: http://www.sara-maria.dk/sundt/laekre-saltede-mandler-med-soedt-tilbehoer/

It is a Wordpress site using CherryFramework with a childtheme and I've tried the following:

  1. adding the opening of the div to title.php and the closing div to footer.php

However, for some reason the div is not using the expected closing div. Instead it is being closed way up higher on the page.

  1. I've created a new functions.php in the childtheme and used the following code:

    function my_content($content) { global $post; return ''.$content.''; }

    add_filter('the_content', 'my_content');

Problem is that this only wraps it around the post and my PHP skills are not very good, so I haven't been able to customize it to include the title and the meta data.

Anyone who can help me how I best can create the custom div?

Thanks, Kasper

Update - copying in loop-single.php on request from dojs:

<?php /* Loop Name: Single */ ?>
<div id="loopTEST">
<?php if (have_posts()) : while (have_posts()) : the_post();
    // The following determines what the post format is and shows the correct file accordingly
    $format = get_post_format();
    get_template_part( 'includes/post-formats/'.$format );
    if($format == '')
        get_template_part( 'includes/post-formats/standard' );
    get_template_part( 'includes/post-formats/share-buttons' );
    wp_link_pages('before=<div class="pagination">&after=</div>');
?>
</div>
<!---removed author block--->

<?php
    get_template_part( 'includes/post-formats/related-posts' );
    comments_template('', true);
    endwhile; endif; 
?>
  • 写回答

1条回答 默认 最新

  • douman9420 2015-03-06 18:18
    关注

    Update

    If you look at the DOM of your site you can clearly see that the title section is found in it's own file.

    Take a look at this HTML

    <div class="row">
        <div class="span12" data-motopress-type="static" data-motopress-static-file="static/static-title.php">
        <section class="title-section">
        <h1 class="title-header">
            Lækre saltede mandler med sødt tilbehør </h1>
        <!-- BEGIN BREADCRUMBS-->
        ...
        <!-- END BREADCRUMBS -->
        </section><!-- .title-section -->
        </div>
    </div>
    

    You would think that you have to add a div to "static/static-title.php", but that would most likely destroy the layout.

    To be honest, the structure of this theme seems horrible to me (which means that the theme is shit), however if you are hell bent on using it you need to find the file (which would most likely be "single.php" in your themes root directory) that includes "static/static-title.php" and add a div on the line above that.


    Okay, well to really see how this builds up your single post pages you might need to go through the included template parts, but try this to start out with.

    <div id="loopTEST">
    <?php if (have_posts()) : while (have_posts()) : the_post();
        $format = get_post_format();
    ?>
    <div> <!-- This should be above the title -->
    <?php
        get_template_part( 'includes/post-formats/'.$format );
        if($format == '')
            get_template_part( 'includes/post-formats/standard' );
    ?>
    </div> <!-- This should be below the post but above the social media buttons -->
    <?php
        get_template_part( 'includes/post-formats/share-buttons' );
        wp_link_pages('before=<div class="pagination">&after=</div>');
    ?>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?