我收到了Wordpress的所有帖子,但帖子中的文字打破了这样:
以下是代码片段:
<?php
global $post;
$args = array(
'posts_per_page' => 10,
'orderby' => 'date'
);
$postslist = get_posts( $args );
if($postslist) {
foreach ( $postslist as $post ) :
setup_postdata( $post );
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$content = apply_filters('the_content', $post->post_content);?>
<h2><?php the_title(); ?></h2>
<p><?php the_date(); ?></p>
<img id="blogtemplate-image" src="<?php echo $url ;?>" />
<p><?php echo $content; ?></p>
<?php endforeach; }
wp_reset_postdata();
?>
如何避免中断并获取所有内容?
提前致谢!
答案 0 :(得分:2)
我自己找到了答案。而不是获取the_excerpt()我必须使用the_content()。 The_excerpt只返回55个字符左右:
<?php
global $post;
$args = array(
'posts_per_page' => 10,
'orderby' => 'date'
);
$postslist = get_posts( $args );
if($postslist) {
foreach ( $postslist as $post ) :
setup_postdata( $post );
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<h2><?php the_title(); ?></h2>
<p><?php the_date(); ?></p>
<img id="blogtemplate-image" src="<?php echo $url ;?>" />
<p><?php echo the_content(); ?></p>
<?php
endforeach;
}
wp_reset_postdata();
?>