自定义 post 类型页面简码无效
Custom post type page shortcode not working
这是我的模板存档中的代码-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();
我在[后面]使用这个简码来调用简码
页面模板在使用页面属性选择时工作正常,但在使用简码时,结果是简码[后面]
在主题的 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' );
并在您的存档中调用短代码-gallery.php,如下所示。
echo do_shortcode( '[behind]' );
这是我的模板存档中的代码-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();
我在[后面]使用这个简码来调用简码
页面模板在使用页面属性选择时工作正常,但在使用简码时,结果是简码[后面]
在主题的 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' );
并在您的存档中调用短代码-gallery.php,如下所示。
echo do_shortcode( '[behind]' );