将变量传递到包含中的另一个变量可能吗?

我正在为自己创建一个新站点, 并很好奇是否有可能将一个变量传递给包含中的另一个变量。我所拥有的是包含条件摘要的一个include。如果没有摘录, 则它将获取the_content并删除所有URL。我只是想通过字数统计。这就是我所拥有的。

如你所见, 我正在尝试传递$ wordcount

主模板:

<?php 
  $wordcount = '10';
  include(locate_template('loop-templates/content-excerpt.php'));
?>

包括:

<?php
  if ( ! has_excerpt() ) {
    $content = wp_trim_words(wp_strip_all_tags( get_the_content(), $wordcount )) ;
    $regex = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@";
    echo preg_replace($regex, ' ', $content);
  }else {
    the_excerpt();
  }
?>

任何帮助将是巨大的!


#1


把它放在function.php中

function print_copntent($wordcount){
if ( ! has_excerpt() ) {
    $content = wp_trim_words(wp_strip_all_tags( get_the_content(), $wordcount )) ;
    $regex = "@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@";
    echo preg_replace($regex, ' ', $content);
  }else {
    the_excerpt();
  }
}

在模板文件中调用函数;

<?php print_content(10); ?>

#2


我是个白痴。我的读音代码

wp_trim_words(wp_strip_all_tags( get_the_content(), $wordcount ))

应该什么时候

wp_strip_all_tags(wp_trim_words( get_the_content(), $wordcount ))

来源:

https://www.srcmini02.com/63754.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37578.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?