自定义文章类型的页面快捷代码不起作用


Custom post type page shortcode not working

这是我的模板archive-gallery.php 中的代码

<?php
/*
Template Name: Gallery
*/
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'bm_custom_loop' );
function bm_custom_loop() {
     $gallery = new WP_Query( array( 'post_type' => 'gallery','posts_per_page' => 7) );
     if ( $gallery -> have_posts() ){
?>
<h1> Behind the scene photo gallery </h1>
<br>
<?php
         while ( $gallery -> have_posts() ){
             $gallery -> the_post();
?>
    <?php $images = get_field('image');
        if( $images ): ?>
            <?php foreach( $images as $image ):?>
                <div id="box"> <img class="galimg" src="<?php echo $image['url']; ?>">
                    <a href="<?php echo $image['url']; ?>"><div id="over">
                        <span id="plus"><i class="fa  fa-2x fa-camera"></i></span>
                    </div></a>
                </div>
        <?php endforeach; ?>
    <?php endif; ?><?php
        } // End IF
     } // End While
} //End Loop
add_shortcode( 'behind', 'bm_custom_loop' ); 
genesis();

我用这个短代码〔背后〕调用短代码

当使用页面属性选择页面模板时,页面模板工作正常,但当使用短代码时,结果是的短代码[behind]

在主题的function.php文件中编写以下代码。

function bm_custom_loop() {
 $gallery = new WP_Query( array( 'post_type' => 'gallery','posts_per_page' => 7) );
 if ( $gallery -> have_posts() ){
?>
<h1> Behind the scene photo gallery </h1>
<br>
<?php
     while ( $gallery -> have_posts() ){
         $gallery -> the_post();
?>
<?php $images = get_field('image');
    if( $images ): ?>
        <?php foreach( $images as $image ):?>
            <div id="box"> <img class="galimg" src="<?php echo $image['url']; ?>">
                <a href="<?php echo $image['url']; ?>"><div id="over">
                    <span id="plus"><i class="fa  fa-2x fa-camera"></i></span>
                </div></a>
            </div>
    <?php endforeach; ?>
<?php endif; ?>
<?php
    } // End IF
 } // End While
} //End Loop
add_shortcode( 'behind', 'bm_custom_loop' );

并像下面这样调用archive-gallery.php中的短代码。

echo do_shortcode( '[behind]' );