当我离开这个短代码与当前的职位ID?
问题描述:
这个shortcode
必须通过指定一个id来调用,例如:[full_dolar id='25000']
带有单个帖子ID。这适用于我放置的任何页面。当我离开这个短代码与当前的职位ID?
我想从shortcode
中删除id参数,所以我必须使用的是[full_dolar]
。
以下是我目前需要id参数的代码。
function post_id_shortcode_func($atts) {
extract(shortcode_atts(array(
'id' => ''
), $atts));
if ((int) $id) {
// start output
ob_start();
$out = '<div class="dolar-shortcode clearfix">';
dolar_get_full_cambio($id);
$out .= ob_get_contents();
$out .= '</div>';
ob_end_clean();
return $out;
}
}
// add shortcode for full dolar [full_dolar]
add_shortcode('full_dolar', 'post_id_shortcode_func');
答
未经测试,我已经一段时间没有使用WordPress的,但是这可能工作:
function post_id_shortcode_func($atts) {
$id = get_the_ID();
if ((int) $id) {
// start output
ob_start();
$out = '<div class="dolar-shortcode clearfix">';
dolar_get_full_cambio($id);
$out .= ob_get_contents();
$out .= '</div>';
ob_end_clean();
return $out;
}
}
// add shortcode for full dolar [full_dolar]
add_shortcode('full_dolar', 'post_id_shortcode_func');
来源:https://developer.wordpress.org/reference/functions/get_the_id/
+0
非常感谢你的工作 –
你尝试'get_post() - > ID'? – Chris
请为我做功能 –