我正在尝试创建一个显示最新帖子的短代码.我使用以下代码作为短代码
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' );
Run Code Online (Sandbox Code Playgroud)
之后,我创建了一个页面,然后我选择了默认页面模板?这是我的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>
Run Code Online (Sandbox Code Playgroud)
以下是我的短代码
[recent-posts limit="3"]
Run Code Online (Sandbox Code Playgroud)
但是当我看到结果时,它会显示一个"预"标签.
请告诉我解决方案.
检查您安装短代码的页面的编辑模式.如果您使用所见即所得编辑器并且处于"可视"模式,则您的短代码可能具有PRE包装器.在"文本"模式下检查它.
<pre>[Blah_shortcode]</pre>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2551 次 |
| 最近记录: |