Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress短代码不会返回html字符串中的变量_Php_Html_Wordpress_Shortcode - Fatal编程技术网

Php Wordpress短代码不会返回html字符串中的变量

Php Wordpress短代码不会返回html字符串中的变量,php,html,wordpress,shortcode,Php,Html,Wordpress,Shortcode,我已经尝试了我能想到的一切。标题显示在内容包装的顶部,html标记保留在它们应该保留的位置 我正在从一个页面执行这个短代码。我需要的标题和一个链接到媒体库中的图像,这样我就可以吐出html显示在一个页面上通过快捷码 add_shortcode( 'ispimg', 'isp_gallery_item' ); function isp_gallery_item( $atts ) { // Attributes $a = shortcode_atts( array( 'id' =>

我已经尝试了我能想到的一切。标题显示在内容包装的顶部,html标记保留在它们应该保留的位置


我正在从一个页面执行这个短代码。我需要的标题和一个链接到媒体库中的图像,这样我就可以吐出html显示在一个页面上通过快捷码

add_shortcode( 'ispimg', 'isp_gallery_item' );

function isp_gallery_item( $atts ) {

// Attributes
$a = shortcode_atts( array(
    'id' => '',
), $atts );


$isp_post_id = get_post($a['id']);
setup_postdata($isp_post_id);

$pt = the_title();

return "<h3>".$pt."</h3>";


wp_reset_postdata();

}
add_shortcode('ispimg','isp_gallery_item');
功能isp_画廊_项目($atts){
//属性
$a=短码_附件(阵列)(
“id'=>”,
)(港币),;
$isp_post_id=get_post($a['id']);
设置发布数据($isp发布id);
$pt=_title();
返回“$pt.”;
wp_reset_postdata();
}

不完全确定这是否是您的问题,但我建议您不要干扰主查询,您可能会因此影响页面的其他部分

使用API函数,如:

功能isp\u画廊\u项目($atts){
//属性
$a=短码_附件(阵列)(
“id'=>”,
)(港币),;
返回sprintf('%s',获取标题($a['id']);
}
添加快捷码('ispimg'、'isp\U gallery\U item');

或者,如果您需要循环,请查看该类。

首先,您的
wp\u reset\u postdata()将不起作用。你的错误是什么(原因不明)?您想要实现什么?return=“.$pt.”。。。和@SamvelAleqsanyan一样-不清楚你想在这里做什么。我需要媒体库中图像的标题和永久链接,这样我就可以通过快捷码在页面上显示html。
function isp_gallery_item( $atts ) {
    // Attributes
    $a = shortcode_atts( array(
        'id' => '',
    ), $atts );

    return sprintf( '<h3>%s</h3>', get_the_title( $a['id'] ) );
}
add_shortcode( 'ispimg', 'isp_gallery_item' );