Lines below image php

2020-05-03 10:24发布

I'm trying to display one line of excerpt from posts beneath the images at the bottom of this website: http://www.wha2wear.com/ This is the php function used to get the images and the excerpt:

<div class="blog">
<h2><span>Sneak peak</span></h2>
<ul>
<?php query_posts('orderby=comment_count&posts_per_page=6'); if ( have_posts() ) :      

while ( have_posts() ) : the_post(); ?>

<li>
<h3 class="short_title"><a title="Post: <?php the_title(); ?>" href="<?php   

the_permalink(); ?>"><?php echo ShortTitle(get_the_title()); ?> </a></h3>

<a href="<?php the_permalink(); ?>"><?php getImage('1'); ?></a>

<a href="<?php the_permalink(); ?>"><?php echo limit_words(get_the_excerpt(), '6');
        echo '...</a>';
        echo '</li>'; ?></a>


<?php endwhile; ?></li>
<?php else : ?>
<p>Sorry, no posts were found.</p>
</ul>


</div>

The problem is on two of the photos the excerpt is showing next to the photo instead if beneath it...thank you!

标签: php wordpress
1条回答
在下西门庆
2楼-- · 2020-05-03 11:27

Your problem is that your display is dependent on the data. A blurb starting with <br> or <p> will wrap, otherwise not. Wrap them in divs to make them line up properly:

<div id="imageDiv"><a href="<?php the_permalink(); ?>"><?php getImage('1'); ?></a></div>

<div id="blurbDiv"><a href="<?php the_permalink(); ?>"><?php echo limit_words(get_the_excerpt(), '6');
        echo '...</a>';
        echo '</li>'; ?></a></div>

You could also just force a line break between the two:

<a href="<?php the_permalink(); ?>"><?php getImage('1'); ?></a>
<br />
<a href="<?php the_permalink(); ?>"><?php echo limit_words(get_the_excerpt(), '6');
        echo '...</a>';
        echo '</li>'; ?></a>
查看更多
登录 后发表回答