如何获取页面标题为shortcode参数的值? 我已编写了接受参数的自定义php脚本, 我可以在参数中将硬编码的镜头代码作为值发送,但必须在参数中发送页面的标题
答案 0 :(得分:1)
以简码发送帖子标题:
[myshortcode title='Web pages']
//简码
function shortcode_myshortcode($atts) {
$atts = shortcode_atts(
array(
'title' => 'no foo',
), $atts);
return $atts['title'];
}
add_shortcode('myshortcode', 'shortcode_myshortcode');
答案 1 :(得分:0)
不确定我是否理解您的问题,但要获取当前帖子的标题,请使用SELECT CONCAT('£ ', n1) AS Total_N1,
CONCAT('£ ', n2) AS Total_N2,
100 * (N1 - N2) / (N1+N2) / 2 as diff
FROM (SELECT SUM(CASE WHEN t1.col_type = 'N1' THEN t2.qty * t1.price ELSE 0 END) as n1,
SUM(CASE WHEN t1.col_type = 'N2' THEN t2.qty * t1.price ELSE 0 END) as n2
FROM t2 INNER JOIN
t1
ON t2.col_id = t1.col_id
) t
。您可以在shortcode函数中使用它,也可以在为您进行的自定义php脚本进行预调用时使用它。
https://developer.wordpress.org/reference/functions/get_the_title/