【问题标题】:Add Columns to Understrap / Underscores Blog Page Template Posts将列添加到 Understrap / Underscores 博客页面模板帖子
【发布时间】:2018-09-19 08:57:05
【问题描述】:

我想自定义 Underscores Wordpress 主题博客模板,以在每个博客文章条目周围包含列。

理想情况下,这些会变成带有分页的帖子网格,但现在我只是想让网格工作。

这是来自 content.php 文件:

<?php
/**
* Post rendering content according to caller of get_template_part.
*
* @package understrap
*/

?>

<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<header class="entry-header">

    <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
    '</a></h2>' ); ?>

    <?php if ( 'post' == get_post_type() ) : ?>

        <div class="entry-meta">
            <?php understrap_posted_on(); ?>
        </div><!-- .entry-meta -->

    <?php endif; ?>

</header><!-- .entry-header -->

<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>

<div class="entry-content">

    <?php
    the_excerpt();
    ?>

    <?php
    wp_link_pages( array(
        'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' 
    ),
        'after'  => '</div>',
    ) );
    ?>

</div><!-- .entry-content -->

<footer class="entry-footer">

    <?php understrap_entry_footer(); ?>

</footer><!-- .entry-footer -->

</article><!-- #post-## -->
    </div>

感谢您的帮助!

【问题讨论】:

    标签: php wordpress bootstrap-4 underscores-wp


    【解决方案1】:

    我假设您在谈论 UnderStrap,而不是 Underscores,对吧?

    要将 Bootstrap 网格 (http://getbootstrap.com/docs/4.1/layout/grid/) 添加到您的文章/博客视图中,您必须做两件事: 第 1 步 在你的循环周围包裹一个外行。 去做这个: 打开主题 index.php 并搜索: &lt;main class="site-main" id="main"&gt;

    在它后面添加开口,这样你就有了:

    <main class="site-main" id="main"><div class="row">
    

    现在在结束标签之前添加结束标签:

    </div></main>
    

    第 2 步 虽然只需要在所有文章周围添加一次外部行包装器,但您需要将 Bootstrap col 类和正确的大小变量添加到您的 loop-templates/content.php 文件中。这样它就适用于循环中的所有文章。

    打开文件并添加:

    <div class="col-6">
    

    就在 &lt;article&gt; 开头标签之前。

    col-6 类的意思是“使用 6/12 的空间,例如 50%。 所以你将有两个并排的文章。 当然你也可以使用col-4 (4/12=33.33%) 将三篇文章并排放置等。

    根据您的需要,另一个好的起点是使用 Bootstrap 卡片组组件: http://getbootstrap.com/docs/4.1/components/card/#card-decks

    【讨论】:

    • 非常感谢 Holger,这非常有效!感谢您的宝贵时间和精彩的框架!
    猜你喜欢
    • 1970-01-01
    • 2016-04-26
    • 2011-11-18
    • 1970-01-01
    • 2023-03-27
    • 2019-11-30
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多