[英]Wordpress blog isn't showing posts. Does adding a custom portfolio post field effect this?
现在我已经完成了两次,没有问题,我有一个使用home.php的主页,另一个使用“ blog-home.php”博客模板的博客,以及所有正确的代码来获取帖子,但这是不显示。 唯一的区别是,我已经向函数添加了自定义投资组合发布字段,这会影响它还是其他? 我可以从主页的最新帖子下访问该帖子,并将代码放在下面,仅此而已。
<?php query_posts("post_per_page=1"); the_post(); ?>
<p><?php the_excerpt(); ?></p>
<?php wp_reset_query(); ?></div>
* 更新:我尝试了另一个代码,但是现在它仅将博客页面显示为帖子。 *
<?php
/*
Template Name: Blog Home
*/
?>
<?php get_header(); ?>
<div id="contentwrapper">
<?php query_posts( array ( 'category_name' => 'Blog', 'posts_per_page' => 5 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="blogentry">
<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </h4>
<?php the_content(); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
也许如果您使用
$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();
代替
query_posts();
如果get_posts对您不起作用,则更改全局查询永远不是一个好主意,请尝试使用WP_Query()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.