我遇到了在 Wordpress 中创建自己的搜索循环的问题。我想要实现的是某些情况下仅显示某些信息:
<?php while ( have_posts() ) : the_post(); echo '<div>'; ?>
<?php if ( in_category('property') ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('main-image-description'); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( in_category('all-developments') ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_field('property-description'); ?>
<span class="launch-brochure">
<a href="<?php the_field('pdf-download-all-developments'); ?>" target="_blank">
<span class="link">Download Brochure</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php if ( is_page() ) { ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<span class="launch">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'boilerplate' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<span class="link">click to launch</span>
<span class="launch-icon"></span>
</a>
</span>
<?php } ?>
<?php echo '</div>'; endwhile; ?>
出现的问题是,它总是会在顶部呈现一两个空标签,这会破坏它的样式,因为每个 div 都有一个虚线边框。有没有办法告诉 Wordpress,如果不满足这些条件,那么不要显示<div>
?
提前感谢您的帮助!
J.P