简体   繁体   English

如何在 PHP 中的摘录周围放置链接?

[英]How can I put a link around my excerpts in PHP?

I'm trying to put a link around my excerpts like on my titles but i'm getting a parse-error on this line:我试图在我的摘录周围加上一个链接,就像我的标题一样,但我在这一行得到了一个解析错误:

echo '<div class="excerpt">''<a href="' the_permalink(); '">' . nectar_excerpt($excerpt_length) . '</a></div>';?>

Here the whole code of my post-element:这是我的后元素的整个代码:

<div class="post-header">
    <h3 class="title">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </h3>
    <span class="meta-author"><?php the_author_posts_link(); ?> </span>
    <span class="meta-category"> | <?php the_category(', '); ?> </span>
    <span class="meta-comment-count"> | <a href="<?php comments_link(); ?>">
        <?php comments_number( esc_html__( 'No Comments','salient'), esc_html__( 'One Comment','salient'), '% '. esc_html__( 'Comments','salient') ); ?></a> 
    </span>
</div>

<?php
    $excerpt_length = ( !empty( $nectar_options['blog_excerpt_length'] ) ) ? 
    intval( $nectar_options['blog_excerpt_length'] ) : 30;
    echo '<div class="excerpt">''<a href="' the_permalink(); '">' . nectar_excerpt($excerpt_length) . '</a></div>';?>
    <div class="meta-tags"> <?php the_tags(''); ?> </div>
    <div class="tags-divider"></div>

Give this a try?试试这个?

echo '<div class="excerpt"><a href="' . the_permalink() . '">' . nectar_excerpt($excerpt_length) . '</a></div>';

In PHP, text strings are merged using the dot character.在 PHP 中,文本字符串使用点字符进行合并。 So if you want to connect them together, you should do this:所以如果你想将它们连接在一起,你应该这样做:

$a = "text1";
$b = "text2";
echo ($a . $b); // prints "text1text2"

Or in your case like this:或者在你的情况下是这样的:

echo "text1" . function() . "text3"; // prints text1text2text3

And if you are using function like string, you don't use the ";"如果您使用 function 之类的字符串,则不要使用“;” character at the end, because it will end the whole line of code.最后的字符,因为它将结束整行代码。

echo "text1" . "text2"; . "text3"; // wrong
echo "text1" . "text2" . "text3"; // correct
echo "text1" . function(); . "text3"; // wrong
echo "text1" . function() . "text3"; // correct

So, just add the dots and remove the semicolon, and it should work.因此,只需添加点并删除分号,它应该可以工作。

echo '<div class="excerpt">' . '<a href="' . the_permalink() . '">' . nectar_excerpt($excerpt_length) . '</a></div>';?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM