Wordpress 短代码返回数字 1?如何删除?

Wordpress Shortcode Returning Number 1? How To Remove?

我想知道是否有人知道为什么以下代码最后返回数字 1?有谁知道如何阻止这种情况发生?

function get_product_images_slider() {
$product_image_output = include( get_stylesheet_directory() . '/product-images-shortcode.php');
return $product_image_output;
}
add_shortcode( 'product-images', 'get_product_images_slider' );

我的包含代码是:

                         <ul class="slick  js-fader">
                            <li>
                                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?>
                                <img src="<?php echo $image[0]; ?>" class="figure" width="425" height="328" itemprop="image" />
                            </li>
                            <?php
                                global $product;
                                $attachment_ids = $product->get_gallery_attachment_ids();

                                foreach( $attachment_ids as $attachment_id ) 
                                { ?>
                                    <li>
                                        <?php
                                            echo wp_get_attachment_image($attachment_id, 'product-image', '', array( "class" => "figure", 'width' => '425', 'height' => '328', 'itemprop' => 'image' ) );
                                        ?>
                                    </li>
                            <?php }
                            ?>
                        </ul>

如果包含成功,include function 总是 returns 第一个,并且您正在将其分配给变量。您将在最后返回此变量。你期望输出什么?

编辑:这是您需要使用的代码:

产品图片-shortcode.php

<?php function productShortcode() { ?>
     <ul class="slick js-fader">
         <li>
             <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?>
             <img src="<?php echo $image[0]; ?>" class="figure" width="425" height="328" itemprop="image" />
        </li>
        <?php
        global $product;
        $attachment_ids = $product->get_gallery_attachment_ids();
        foreach( $attachment_ids as $attachment_id ) 
        { ?>
            <li>
                <?php
                echo wp_get_attachment_image($attachment_id, 'product-image', '', array( "class" => "figure", 'width' => '425', 'height' => '328', 'itemprop' => 'image' ) );
                ?>
            </li>
        <?php
        } ?>
    </ul>
<?php } ?>

functions.php

function get_product_images_slider() {
    include( get_stylesheet_directory() . '/product-images-shortcode.php');
    return productShortcode();
}
add_shortcode( 'product-images', 'get_product_images_slider' );

因此,我们使用的是 include 中的代码,而不是直接返回 include 的值。