我努力了,尝试了很多东西,但没有什么对我有用......
有人可以帮帮我吗?
我拥有:每行3列,但它只在循环中创建1行... 我想要的:3列包裹在一个新行
这是我的代码:
<?php get_header(); ?>
<div class="row main-row">
<div class="col-md-9 main-content">
<div class="row post-row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="post">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( '', array( 'class' => 'img-responsive post-thumbnail' ) );
}
?>
<div class="post-content">
<h3 class="post-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();?></a>
</h3>
<?php the_excerpt(); ?>
<div class="row">
<div class="col-md-6">
<div class="rating">
<?php
echo do_shortcode('[mr_rating_result show_count="false"]');
?>
</div>
</div>
<div class="col-md-6">
<div class="views">
<p><i class="fa fa-eye"></i> <?php echo_views(get_the_ID()); ?> <?php _e('views', 'huge-fights'); ?></p>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
$wplinkpages = array(
'before' => '<p>' . __( 'Pages:', 'huge-fights' ),
'after' => '</p>',
'link_before' => '',
'link_after' => '',
'separator' => ' ',
'nextpagelink' => __( 'Next page', 'huge-fights' ),
'previouspagelink' => __( 'Previous page', 'huge-fights' ),
'pagelink' => '%',
'echo' => 1
);
wp_link_pages( $wplinkpages );
?>
<?php
$counter = 0;
$counter++;
if ($counter % 3 == 0) {
echo '</div><div class="row">';
}
?>
<?php endwhile; else: ?>
</div>
<h1 class="content-title"><?php _e('Nothing found', 'huge-fights') ?></h1>
<p><?php _e('Nothing found here, sorry!', 'huge-fights'); ?></p>
<?php endif; ?>
</div>
</div>
<div class="col-md-3 hidden-sm hidden-xs sidebar">
<?php get_sidebar('primary'); ?>
</div>
</div>
<?php get_footer(); ?>
感谢您的帮助!
答案 0 :(得分:0)
找到解决方案:
我把$ counter = 0;在while循环之外,因为当它在while循环中时它只会返回&#39; 1&#39;。因为它处于循环中。
所以好的代码应该是:
<?php get_header(); ?>
$counter = 0;
<div class="row main-row">
<div class="col-md-9 main-content">
<div class="row post-row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="post">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( '', array( 'class' => 'img-responsive post-thumbnail' ) );
}
?>
<div class="post-content">
<h3 class="post-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();?></a>
</h3>
<?php the_excerpt(); ?>
<div class="row">
<div class="col-md-6">
<div class="rating">
<?php
echo do_shortcode('[mr_rating_result show_count="false"]');
?>
</div>
</div>
<div class="col-md-6">
<div class="views">
<p><i class="fa fa-eye"></i> <?php echo_views(get_the_ID()); ?> <?php _e('views', 'huge-fights'); ?></p>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
$wplinkpages = array(
'before' => '<p>' . __( 'Pages:', 'huge-fights' ),
'after' => '</p>',
'link_before' => '',
'link_after' => '',
'separator' => ' ',
'nextpagelink' => __( 'Next page', 'huge-fights' ),
'previouspagelink' => __( 'Previous page', 'huge-fights' ),
'pagelink' => '%',
'echo' => 1
);
wp_link_pages( $wplinkpages );
?>
<?php
$counter++;
if ($counter % 3 == 0) {
echo '</div><div class="row">';
}
?>
<?php endwhile; else: ?>
</div>
<h1 class="content-title"><?php _e('Nothing found', 'huge-fights') ?></h1>
<p><?php _e('Nothing found here, sorry!', 'huge-fights'); ?></p>
<?php endif; ?>
</div>
</div>
<div class="col-md-3 hidden-sm hidden-xs sidebar">
<?php get_sidebar('primary'); ?>
</div>
</div>
<?php get_footer(); ?>