【发布时间】:2019-02-13 02:51:45
【问题描述】:
目前我正在使用 Understrap 使用 Bootstrap 4 框架创建一个带有 wordpress 的网站。我正在尝试创建一个不错的博客网格,而不仅仅是一个标准的帖子循环。
为了达到我想要的结果,我使用了 BS4 'Card Deck'。但是我似乎用 flex 得到了一些相当奇怪的结果。我想知道是否有人遇到过这种情况,或者可以看到我的代码中可能导致错误的任何明显内容?
以下是我调整的代码及其对应的文件。
Content.php
<?php
/**
* Post rendering content according to caller of get_template_part.
*
* @package understrap
*/
?>
<div id="post-<?php the_ID(); ?>" class="card">
<? $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full', false )[0] ?>
<img class="card-img-top" src="<?php echo $thumb_url; ?>" alt="Card image cap">
<div class="card-body">
<?php the_title( sprintf( '<h5 class="card-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
'</a></h5>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<?php endif; ?>
<p class="card-text">
<?php echo get_the_excerpt(); ?>
</p><!-- .entry-content -->
<p class="card-footer">
<small class="text-muted">
<?php understrap_posted_on(); ?>
<?php understrap_entry_footer(); ?>
</small>
</p><!-- .entry-meta -->
</div><!-- <<< ITS IMPORTANT TO REMEMBER THIS -->
</div><!-- #post-## -->
Index.php
<main class="site-main" id="main">
<!-- Introduce Bootstrap 4 Card Deck -->
<div class="row">
<div class="card-deck">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'loop-templates/content', get_post_format() );
?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
<?php endif; ?>
</div>
<!-- End Card Deck -->
</div>
</main>
<!-- #main -->
免责声明 我通常不会在 wp 中涉足这么深,所以如果你看到任何不合适的东西,那就是原因。
感谢您的帮助。 -B。
编辑:2018 年 9 月 7 日
忘记添加该死的
</div>,那是我生命中的两个小时,我再也回不来了。 FML。
【问题讨论】:
标签: php wordpress bootstrap-4