我正在开发Onepress的儿童主题。我需要在主标签内的容器div中显示所有帖子。我在代码中做到了, 但是, 一些帖子在浏览器的main标签之外呈现。它破坏了布局。任何帮助将深表感谢!
这是我文件中的代码:
<div id="content" class="site-content">
<?php onepress_breadcrumb(); ?>
<div id="content-inside" class="container">
<div id="primary" class="content-area">
<main class="site-main" role="main">
<div class="container">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<div class="container">
<?php get_template_part( 'template-parts/content', 'custom' ); ?>
</div>
<?php endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
</div><!--#content-inside -->
</div><!-- #content -->
自定义模板文件中的代码:
<article class="row entry-article col-sm-12 col-md-12 w-100" id="post-<?php the_ID(); ?>" <?php post_class( array('list-article', 'clearfix') ); ?>>
<div class="col-sm-12 col-md-3 thumb-custom-container">
<a href="<?php echo esc_url( get_permalink() ); ?>">
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'onepress-blog-medium' );
} else {
echo '<img class="thumb-custom" alt="" src="'. get_template_directory_uri() . '/assets/images/placholder2.png' .'">';
}
?>
</a>
</div>
<div class="col-sm-12 col-md-6">
<div class="row">
<div class="col-sm-12">
<header class="entry-header col-sm-12">
<?php /* the_title( sprintf( '<p><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></p>' ); */ ?>
<?php
$post_id = get_the_ID();
echo '<h2 class="entry-price">R$ ' . get_post_meta($post_id, 'real_state_price', true) . '</h2>';
$post_id = get_the_ID();
echo '<small class="entry-features">'
. get_post_meta($post_id, 'real_state_size', true) . ' m², Square '
. get_post_meta($post_id, 'real_state_square', true) . ', Number '
. get_post_meta($post_id, 'real_state_number', true)
. '</small>';
?>
</header><!-- .entry-header -->
<div class="col-sm-12 entry-excerpt">
<?php
the_excerpt();
?>
</div>
</div>
<div class="col-sm-12 entry-link">
<button class="btn entry-btn-details" href="<?php echo esc_url( get_permalink($post_id) ); ?>">+</button>
<span><a class="entry-read-more" href="<?php echo esc_url( get_permalink($post_id) ); ?>">
Read More
</a></span>
</div>
</div>
</div>
<!-- PICTURE FROM CATEGORIE IMAGES PLUGIN -->
<div class="col-sm-12 col-md-3">
<div class="col-sm-12 entry-residencial">
<a href="<?php echo esc_url( get_permalink() ); ?>">
<?php
$residencial_terms = get_the_terms($post_id, 'residencials');
foreach ($residencial_terms as $term) : ?>
<img src="<?php echo z_taxonomy_image_url($term->term_id); ?>" />
<?php endforeach; ?>
</a>
</div>
<div class="col-sm-12">
<?php
// Teste para identificar a cidade e chamar o modal de contato correspondente
$cities_terms = get_the_terms($post_id, 'city');
if (!empty($cities_terms)) :
if (is_array($cities_terms)) :
foreach ($cities_terms as $term) :
$term_name = $term->name;
$city = $term_name == 'City01' ? 'firstModal' : 'secondModal';
endforeach;
else :
$city = $term;
endif;
else :
$city = 'generalModal';
endif;
?>
<button type="button" class="btn entry-btn" data-toggle="modal" data-target="#<?php echo $city; ?>">
Contact
</button>
</div>
</div>
</div><!-- entry content -->
这是在浏览器中呈现的代码:
<div id="content" class="site-content">
<?php onepress_breadcrumb(); ?>
<div id="content-inside" class="container">
<div id="primary" class="content-area">
<main class="site-main search-page" role="main">
<div class="container">
SOME POSTS HERE
</div>
</main><!-- #main -->
<!-- OTHER POSTS ARE INCORRECTLY HERE -->
<div class="container">
INCORRECTLY PLACED POSTS
</div><!-- incorrectly placed posts -->
</div><!-- #primary -->
</div><!--#content-inside -->
</div><!-- #content -->
那么, 有人知道如何解决此错误吗?感谢大伙们!
#1
看起来你的代码中包含一些无效的HTML。
到目前为止, 我可以发现这种不一致:
<div class="col-sm-12 entry-excerpt">
<?php
the_excerpt();
?>
</div>
</div>
评论前必须登录!
注册