简码出现在内容的顶部
shortcode appears on the top of the content
我创建了一个短代码,但由于某种原因它出现在主要内容上方,就在页面内容开始之前。
function aran_show_expertises( ) {
$expertises = new WP_Query( 'post_type=aran_expertises' );
// The loop:
if( $expertises -> have_posts() ):
while( $expertises -> have_posts() ): $expertises -> the_post();
$slider =
"<script type='text/javascript'>
jQuery(document).ready(function($){
$(window).load(function() {
$('.flexslider').flexslider({
animation: 'slide',
animationLoop: false,
itemWidth: 210,
itemMargin: 5
});
});
});
</script>
<div class='flexslider'>
<ul class='slides'>
<li>
<span> " . the_title() . "</span>
</li>
</ul>
</div>";
endwhile;
wp_reset_postdata();
else:
$slider = "no posts";
endif;
return $slider;
}
add_shortcode( 'expertises_slider', 'aran_show_expertises' );
一件奇怪的事 - 当 if 语句 returns 为假时,它不会发生。
知道发生了什么事吗?
我设法通过将 the_title()
更改为 get_the_title()
来解决这个问题,因为我输出的是标题而不是 return。
我创建了一个短代码,但由于某种原因它出现在主要内容上方,就在页面内容开始之前。
function aran_show_expertises( ) {
$expertises = new WP_Query( 'post_type=aran_expertises' );
// The loop:
if( $expertises -> have_posts() ):
while( $expertises -> have_posts() ): $expertises -> the_post();
$slider =
"<script type='text/javascript'>
jQuery(document).ready(function($){
$(window).load(function() {
$('.flexslider').flexslider({
animation: 'slide',
animationLoop: false,
itemWidth: 210,
itemMargin: 5
});
});
});
</script>
<div class='flexslider'>
<ul class='slides'>
<li>
<span> " . the_title() . "</span>
</li>
</ul>
</div>";
endwhile;
wp_reset_postdata();
else:
$slider = "no posts";
endif;
return $slider;
}
add_shortcode( 'expertises_slider', 'aran_show_expertises' );
一件奇怪的事 - 当 if 语句 returns 为假时,它不会发生。
知道发生了什么事吗?
我设法通过将 the_title()
更改为 get_the_title()
来解决这个问题,因为我输出的是标题而不是 return。