我使用此脚本显示相关帖子:
<!-- Related Posts START-->
<?php
$query = get_max_related_posts();
if ( $query ) {
?>
<div class="td_block_wrap td_block_7 td_block_widget td_uid_3_5de39f94df644_rand td-pb-border-top td_block_template_1">
<h4 class="block-title">
<span class="td-pulldown-size">Berita Terkait</span>
</h4>
<div class="td_block_inner">
<div class="td-block-row">
<?php while ( $query->have_posts() ) { $query->the_post(); ?>
<div class="td-block-span6">
<div class="td_module_6 td_module_wrap td-animation-stack">
<div class="td-module-thumb">
<a href="<?php the_permalink(); ?>" rel="bookmark" class="td-image-wrap" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,75) ); ?>
</a>
</div>
<div class="item-details">
<h3 class="entry-title td-module-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" ><?php the_title(); ?></a>
</h3>
</div>
</div>
</div>
<?php } wp_reset_postdata(); ?>
</div>
</div>
</div>
<?php } ?>
<!-- Related Posts END -->
脚本显示如下html:
<div class="td_block_inner">
<div class="td-block-row">
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
</div>
</div>
如何让我的相关帖子脚本显示如下html:
<div class="td_block_inner">
<div class="td-block-row">
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
</div>
<div class="td-block-row">
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
</div>
<div class="td-block-row">
<div class="td-block-span6">...</div>
<div class="td-block-span6">...</div>
</div>
</div>
最合适的回答,由SO网友:Gopala krishnan 整理而成
像这样重写代码。这将按预期显示代码。
<!-- Related Posts START-->
<?php
$query = get_max_related_posts();
if ( $query ) {
$i=1;
?>
<div class="td_block_wrap td_block_7 td_block_widget td_uid_3_5de39f94df644_rand td-pb-border-top td_block_template_1">
<h4 class="block-title">
<span class="td-pulldown-size">Berita Terkait</span>
</h4>
<div class="td_block_inner">
<?php while ( $query->have_posts() ) { $query->the_post();
if($i%2!=0){?>
<div class="td-block-row"><?php
}?>
<div class="td-block-span6">
<div class="td_module_6 td_module_wrap td-animation-stack">
<div class="td-module-thumb">
<a href="<?php the_permalink(); ?>" rel="bookmark" class="td-image-wrap" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(100,75) ); ?>
</a>
</div>
<div class="item-details">
<h3 class="entry-title td-module-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" ><?php the_title(); ?></a>
</h3>
</div>
</div>
</div><?php
if($i%2==0){ ?>
</div><?php
}
$i++;
} wp_reset_postdata(); ?>
</div>
</div>
<?php } ?>
<!-- Related Posts END -->