全球主机交流论坛

标题: 问个wordpress变量问题 [打印本页]

作者: vc168    时间: 2017-9-16 21:02
标题: 问个wordpress变量问题
  1. function sc_send($comment_id)
  2. {
  3. $text = '皇上有新的奏章待批阅';
  4. $comment = get_comment($comment_id);
  5. $desp = $comment->comment_content;
  6. $key = 'SCU10446Tehudsfsldfjoods20302d47b1fbdb7597bd07bd61d6';
  7. $postdata = http_build_query(
  8. array(
  9. 'text' => $text,
  10. 'desp' => $desp
  11. )
  12. );
  13. $opts = array('http' =>
  14. array(
  15. 'method' => 'POST',
  16. 'header' => 'Content-type: application/x-www-form-urlencoded',
  17. 'content' => $postdata
  18. )
  19. );
  20. $context = stream_context_create($opts);
  21. return $result = file_get_contents('http://sc.ftqq.com/'.$key.'.send', false, $context);
  22. }
  23. add_action('comment_post', 'sc_send', 19, 2);
复制代码

发送消息的时候,调用$text和$desp,我想在$desp前面再加点东西,怎么加,比方说我要加个文章ID  get_the_ID(),求诸位大佬赐教。
作者: 地瓜侠    时间: 2017-9-16 21:02
第5行
  1. $desp = get_the_ID().$comment->comment_content;
复制代码

或者第10行
  1. 'desp' => get_the_ID().$desp
复制代码

作者: vc168    时间: 2017-9-17 08:45
地瓜侠 发表于 2017-9-16 21:31
第5行

或者第10行

谢谢大佬,这写法没错,不过get_the_ID()获取不到值,不知道为啥,还是谢谢你。
作者: 地瓜侠    时间: 2017-9-17 09:32
vc168 发表于 2017-9-17 08:45
谢谢大佬,这写法没错,不过get_the_ID()获取不到值,不知道为啥,还是谢谢你。 ...

我的失误,第5行改成
  1. $desp =  $comment->comment_post_ID.$comment->comment_content;
复制代码

$comment->comment_post_ID就是获取该评论对应的文章ID,get_the_ID需要在$post循环中才生效
作者: vc168    时间: 2017-9-17 10:34
地瓜侠 发表于 2017-9-17 09:32
我的失误,第5行改成

$comment->comment_post_ID就是获取该评论对应的文章ID,get_the_ID需要在$post循 ...

太感谢了,大佬人真好。。。
作者: 气味    时间: 2017-9-19 14:13
地瓜侠 发表于 2017-9-17 09:32
我的失误,第5行改成

$comment->comment_post_ID就是获取该评论对应的文章ID,get_the_ID需要在$post循 ...

厉害了




欢迎光临 全球主机交流论坛 (https://loc.1226.eu.org/) Powered by Discuz! X3.4