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

Wrap wordpress post and title in custom div

我正在尝试为微格式准备一个博客,所以我需要一个 div 从标题上方开始并在社交分享按钮上方(以及元数据、日期、作者、# of视图等)- 请参阅站点以供参考:http://www.sara-maria.dk/sundt/laekre-saltede-mandler-med-soedt-tilbehoer/

这是一个使用带有子主题的 CherryFramework 的 Wordpress 网站,我尝试了以下方法:

  1. 将 div 的开盘添加到 title.php,将 div 的收盘添加到 footer.php

但是,由于某些原因 div 没有使用预期的结束 div。相反,它在页面上被关闭得更高。

  1. 我在子主题中创建了一个新的 functions.php 并使用了以下代码:

    函数my_content($内容){ 全球$post; return ''.$content.''; }

    add_filter('the_content', 'my_content');

问题是这只围绕着 post 而我的 PHP 技能不是很好,所以我无法自定义它以包含标题和元数据.

任何人都可以帮助我如何最好地创建自定义 div?

谢谢, 卡斯帕

更新 - 根据 dojs 的要求复制到 loop-single.php:

<?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; 
?>

更新

如果您查看您网站的 DOM,您可以清楚地看到标题部分位于它自己的文件中。

看看这个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>

你会认为你必须添加一个 div 到 "static/static-title.php",但这很可能会破坏布局。

老实说,这个主题的结构对我来说似乎很糟糕(这意味着主题很糟糕),但是如果你一心想使用它,你需要找到文件(这很可能是 "single.php" 在你的主题根目录中),其中包括 "static/static-title.php" 并在上面的行上添加一个 div。


好吧,要真正了解这如何构建您的单个 post 页面,您可能需要浏览包含的模板部分,但请尝试从这里开始。

<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>