douben7260 2016-04-05 14:40
浏览 52
已采纳

PHP图像和文本之间的新线

I checked a related question and I saw the syntax for a new line is:

"
"

However, I don't know how to add that to the code of my website:

<h2><span>Sneak peak</span></h2>
<ul>
<?php query_posts('orderby=post_date&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>
<?php endif; ?>


</ul>

This is my website, and what I want to do is putting the text down the images in "Sneak peak" in a new line.

Thanks a lot :)

  • 写回答

2条回答 默认 最新

  • duanlvxi8652 2016-04-05 14:49
    关注

    This is your image:

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

    And this is the excerpt:

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

    In HTML, to make a new line, you write:

    <br><!-- br is short for "break" -->
    

    So to put a new line between the image and text, simply write:

    <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>
    

    That being said, better practice would be to make your image a block styled element with CSS and then it will fill the width, forcing the text onto a new line.

    As I'm not clear on what the function getImage() does, here would be my solution:

    <a href="<?php the_permalink(); ?>">
        <div class="imageContainer">
            <?php getImage("1"); ?>
        </div>
    </a>
    

    And with CSS:

    .imageContainer {
        display:block;
        text-align:center;
    }
    

    This will keep the dimensions of your image, center it, and then also force the text onto a new line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?