以下是我的模板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();
我使用这个短代码[后面]来调用短代码
使用页面属性选择页面模板时工作正常,但使用短代码时,结果是短代码[后面]
答案 0 :(得分:1)
在主题的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]' );