在短代码问题中调用数组

时间:2014-10-02 10:29:37

标签: php arrays wordpress shortcode

我将多个模板上的一些重复代码区域压缩成一个我可以轻松重用的短代码。

我将精选图片网址称为内联背景图片样式,效果很棒!这是代码。

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
     <?php while (have_posts()) : the_post(); ?>
         <div class="single-casestudy" style="background-image: url('<?php echo $image[0]; ?>'); background-size: 100%;">
              <div class="case-study-content">
                  <h4><?php the_title(); ?></h4>
                  <p><?php echo excerpt(22); ?></p>
              </div>
         </div>
     <?php endwhile ; ?>

当不在短代码中时,这可以正常工作,我可以看到我的特色图像作为现场网站的背景,但是当把它放入短代码功能时,它没有错误,它只是没有。工作!下面是我用于短代码功能的代码。似乎$ image [0]没有将任何数据传入数组。

function otherinfo_function() {
            $args = array( 'post_type' => 'casestudy', 
                                    'posts_per_page' => -1,
                                    'orderby' => menu_order,
                                    'order' => RAND
                                );

            query_posts($args);

            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),'single-post-thumbnail' );
            while (have_posts()) : the_post();

            echo $image[0];
                $output = $output . '<div class="single-casestudy" style="background-image: url(' . $image[0] .'); background-size: 100%;">';
                    $output = $output . '<div class="case-study-content">';

                        $output = $output . '<h4>' . get_the_title() . '</h4>';
                        $output = $output . '<p>' . excerpt(22) . '</p>';

                    $output = $output . '</div>';
                $output = $output . '</div>';

            endwhile ;

        $output = $output . '</div>';
return $output;
}

add_shortcode('otherinfo', 'otherinfo_function');

如果有人能提供帮助那就太棒了!

萨姆

0 个答案:

没有答案
相关问题