首页 文章

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

提问于
浏览
-2

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

这是一个使用CherryFramework和一个childtheme的Wordpress网站,我尝试了以下内容:

  • 将div的开头添加到title.php,将结束div添加到footer.php

但是,由于某种原因,div没有使用预期的结束div . 相反,它在页面上的关闭方式更高 .

  • 我在childtheme中创建了一个新的functions.php并使用了以下代码:

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

add_filter('the_content','my_content');

问题是这只包围了帖子,我的PHP技能不是很好,所以我无法自定义它以包含 Headers 和元数据 .

任何可以帮助我最好的人都可以创建自定义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; 
?>

1 回答

  • 1

    Update

    如果您查看网站的DOM,您可以清楚地看到 Headers 部分位于其自己的文件中 .

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


    好的,要真正了解这是如何构建您的单个帖子页面,您可能需要通过包含的模板部分,但尝试这一点开始 .

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

相关问题