0

我在 211 的 index.php 文件中使用下面的代码

get_header(); ?>

    <div id="primary">
        <div id="content" role="main">

        <?php if ( have_posts() ) : ?>

            <?php twentyeleven_content_nav( 'nav-above' ); ?>

            <?php query_posts('cat=4&amp;showposts='.get_option('posts_per_page')); ?>

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>
            <div class="post-thumb-title">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
            <p class="thumb-title"><?php the_title(); ?></p>
            </div>                  

            <?php endwhile; ?>

            <?php twentyeleven_content_nav( 'nav-below' ); ?>

        <?php else : ?>

            <article id="post-0" class="post no-results not-found">
                <header class="entry-header">
                    <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
                </header><!-- .entry-header -->

                <div class="entry-content">
                    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
                    <?php get_search_form(); ?>
                </div><!-- .entry-content -->
            </article><!-- #post-0 -->

        <?php endif; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

正如您从上面的代码中看到的那样,我只显示 Cat ID = 4 的帖子,并且我使用 css 将标题覆盖在使用自定义大小的函数“the_post_thumbnail”生成的图像缩略图上。问题是首页只显示帖子的标题和缩略图,只显示第一个帖子。

您可以在这里查看网站:http: //fusion.fusionconstruction.co.uk/

选择类别 ID 4 的其他帖子的链接:

http://fusion.fusionconstruction.co.uk/fusion-media-at-revolution-round-1/

http://fusion.fusionconstruction.co.uk/fusion-launch-new-website-for-dean-downing/

我想显示所有类似于第一个的帖子。

谢谢!

4

1 回答 1

1
<?php query_posts('cat=4&amp;showposts='.get_option('posts_per_page')); ?>

应该是

<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>

也就是说,您不应该对 & 符号进行 urlencode。希望这是弄乱您的查询的原因。

此外,the_post_thumbnail()将显示帖子的特色图片,因此要生成缩略图,您需要确保所有帖子都有特色图片。

于 2012-09-24T00:28:52.177 回答