我在使用此短代码插件时遇到问题。警告:非法的字符串偏移量'title'

问题描述 投票:1回答:1

我有一个wordpress网站,我正在使用一个使用shortcode作为窗口小部件的插件来提取最近的博客文章。在该列中,我收到一条错误消息:

警告:/home3/xxxxx/xxxx.com/wp-content/plugins/recent-blogs-shortcode/recent-blogs-shortcode.php在第44行上的非法字符串偏移量'title',]

所以标题将是博客文章标题,但我在解决它时遇到了麻烦。

add_shortcode('recent-blogs','cp_sidebar_recent_blogs_shortcode');

function cp_sidebar_recent_blogs_shortcode( $atts, $content = null ) {

    // shortcode_atts will only allow us to supply 1 default; for the horizontal layout submitted with no title, use a different default
    $title_default = '';
    if ($atts['title'] == 'Related Posts' && $atts['layout'] == 'horizontal' ) {
        $title_default = 'Related Posts';
    }
    else {
        $title_default = 'Recent Posts';
    }

我有一个wordpress网站,我正在使用一个使用shortcode作为窗口小部件的插件来提取最近的博客文章。在该列中,我收到一条错误消息:警告:/ ...

php wordpress warnings shortcode
1个回答
0
投票

仔细检查您的$atts变量实际上是一个数组。您收到的错误是因为您试图引用非数组变量的数组键$atts['title']$atts['layout']

© www.soinside.com 2019 - 2024. All rights reserved.