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

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?