我正在尝试创建一个短代码来显示最新的帖子。我使用了以下代码作为短代码
function my_recent_posts_shortcode( $atts ) {
extract( shortcode_atts( array(
'limit' => 5
), $atts,'recent-posts' ) );
$q = new WP_Query(
array('posts_per_page'=>'.$limit.','post_type'=>'post')
);
$list = '';
while($q->have_posts()):$q->the_post();
$list .= '<div class="post">
<img class="img_border img_border_b img_fl" src="'.get_template_directory_uri().'/images/blog/01.jpg" alt="Post Image 1" />
<div class="post_content">
<h2><a href="'.get_permalink().'">'.get_the_title().'</a></h2>
'.the_content().'
<a class="more" href="fullpost.html">More</a>
</div>
<div class="clear"></div>
</div>';
endwhile;
wp_reset_query();
return $list;
}
add_shortcode( 'recent-posts', 'my_recent_posts_shortcode' );
之后我创建了一个页面并选择默认页面模板?这是我的 page.php 模板循环
<div id="templatemo_content" class="left">
<?php if(have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?Php the_content();?>
<?php endwhile; ?>
<?php endif; ?>
</div>
以下是我的简码
[recent-posts limit="3"]
但是当我看到结果时,它显示一个“pre”标签。
请告诉我解决方案。
检查您安装短代码的相关页面的编辑模式。
如果您使用所见即所得编辑器并且处于“可视”模式,您的短代码可能具有 PRE 包装器。在“文本”模式下检查。
<pre>[Blah_shortcode]</pre>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)