0

现在我已经做了几次没有问题,我有一个使用 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(); ?>
4

1 回答 1

0

也许如果你使用

$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();

反而

query_posts();

如果 get_posts 不适合您尝试使用 WP_Query() 更改全局查询绝不是一个好主意

于 2012-04-13T13:00:23.940 回答