如何在PHP中为我的摘录添加链接?

如何在PHP中为我的摘录添加链接?,php,wordpress,Php,Wordpress,我试图在我的摘录周围放置一个链接,如在我的标题上,但我在这一行遇到一个解析错误: echo '<div class="excerpt">''<a href="' the_permalink(); '">' . nectar_excerpt($excerpt_length) . '</a></div>';?> echo''”;?> 这里是my post元素的全部代码: <div class="post-header">

我试图在我的摘录周围放置一个链接,如在我的标题上,但我在这一行遇到一个解析错误:

echo '<div class="excerpt">''<a href="' the_permalink(); '">' . nectar_excerpt($excerpt_length) . '</a></div>';?>
echo''”;?>
这里是my post元素的全部代码:

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

|  
|  
试试看

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

在PHP中,使用点字符合并文本字符串。因此,如果要将它们连接在一起,应执行以下操作:

$a = "text1";
$b = "text2";
echo ($a . $b); // prints "text1text2"
或者在你这样的情况下:

echo "text1" . function() . "text3"; // prints text1text2text3
如果您使用的是类似字符串的函数,那么就不要在末尾使用“;”字符,因为它将结束整行代码

echo "text1" . "text2"; . "text3"; // wrong
echo "text1" . "text2" . "text3"; // correct
echo "text1" . function(); . "text3"; // wrong
echo "text1" . function() . "text3"; // correct
所以,只需添加点并删除分号,就可以了

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