简体   繁体   English

如何在PHP中返回字符串时包含变量?

[英]How do I include a variable while returning a string in PHP?

I created a function that returns custom excerpts for a Wordpress template. 我创建了一个函数,该函数返回Wordpress模板的自定义摘录。 When returning that function, I want to include a "Read more" linking to the original article but can't get it to work. 返回该函数时,我想包含指向原始文章的“更多内容”链接,但无法使其正常工作。

When I return $link itself, I get the clean web address. 当我返回$ link本身时,我得到了干净的网址。

My code so far: 到目前为止,我的代码:

$link = the_permalink();
return implode(' ', array_slice($words, 0, 50))."<br><a href=\"".$link."\" target='_blank'>Read More</a>";

Custom Excerpt Length and More Link 自定义摘录长度和更多链接

// custom excerpt length
function custom_excerpt_length( $length ) {
   return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

// add more link to excerpt
function custom_excerpt_more($more) {
   global $post;
   return '<a class="more-link" href="'. get_permalink($post->ID) . '">'. __('Read More', 'exclutips') .'</a>';
}
add_filter('excerpt_more', 'custom_excerpt_more');

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

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