显示邮件附件时出现奇怪的字符串偏移量错误

时间:2014-05-17 作者:Jordan

我正在尝试创建一个图库页面,该页面从特定类别中获取图像附件并显示它们。这是可行的,但我有一个问题,似乎我试图从返回的附件图像中排除某些附件类型。

我还使用WCK插件为博客帖子创建一些自定义字段,以便在不同位置显示不同大小的图像。在主页上有一个更方形的,在博客页面上有一个瘦的,在实际的帖子页面上有一个稍大一些的瘦版本的图像。下面是我如何调用附件的,在那里您将看到我如何尝试排除这些图像。

// WP_Query arguments
    $args = array (
        \'post_type\'               => \'post\',
        \'pagination\'             => false,
        \'posts_per_page\'     => \'99\',
        \'category_name\' => \'family\'
    );

    // The Query
    $query = new WP_Query( $args );

    // The Loop
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post();

            $thumb_ID = get_post_thumbnail_id( $post->ID );
            $blogimages = get_post_meta( get_the_ID(), \'blogimages\', true ); 
            if ( $images = get_children(array(
                    \'post_parent\' => $post->ID,
                    \'post_type\' => \'attachment\',
                    \'post_mime_type\' => \'image\',
                    \'exclude\' => [$thumb_ID,$blogimages[0][\'blog-image-inside\'],$blogimages[0][\'blog-image-front\'],$blogimages[0][\'blog-image-main\']],
                ))) : 
                foreach( $images as $image ) : 
                    echo \'<div class="item">\';
                    echo \'<a href="\'.wp_get_attachment_url($image->ID).\'" rel="nivo">\';
                    echo wp_get_attachment_image($image->ID, \'full\');
                    echo \'</a>\';
                    echo \'</div>\';
                    endforeach;
        else: // No images
            //This post has no attached images
        endif;
        }
    }
    // Restore original Post Data
    wp_reset_postdata();
我认为问题在于,这些图片并没有设置在那些博客帖子上,所以它有一个问题,也许是因为它们被设置为未定义?如何修复此问题,以便在未上载图像时将其排除,而在上载图像时仍将其排除。

顺便说一句,我所遇到的错误是这样反复出现的,我猜想它多次抓取博客帖子并试图抓取其附件

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Warning: Illegal string offset \'blog-image-inside\' in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Warning: Illegal string offset \'blog-image-front\' in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Warning: Illegal string offset \'blog-image-main\' in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

Notice: Uninitialized string offset: 0 in /Applications/MAMP/htdocs/karmen-noel/wp-content/themes/karmen_noel/page-galleries-family.php on line 50

1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

既然你用了true 的参数get_post_meta, $blogimages 将是单个数组,而不是多维数组。

因此$blogimages[0][\'blog-image-inside\'], 仅使用$blogimages[\'blog-image-inside\'].

为了保持绝对的理智,您可能还需要检查$blogimages 使用前:

\'exclude\' => [
    $thumb_ID,
    isset( $blogimages[\'blog-image-inside\'] ) ? $blogimages[\'blog-image-inside\'] : 0,
    isset( $blogimages[\'blog-image-front\'] ) ? $blogimages[\'blog-image-front\'] : 0,
    isset( $blogimages[\'blog-image-main\'] ) ? $blogimages[\'blog-image-main\'] : 0
],

结束

相关推荐

REGISTER_POST_TYPE EXCLUDE_FROM_SEARCH参数不起作用

但是,我有一个使用此代码注册的帖子类型\'exclude_from_search\' => true 似乎没有任何效果,因为我仍然在搜索页面中找到输出。我是不是犯了什么错误?add_action(\'init\', \'abundant_life_slides_register\'); function abundant_life_slides_register() { $args = array( \'label\' => \'Slides\'