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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?