我在 twentyeleven 的 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&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/
我想显示所有与第一个相似的帖子。
谢谢!
最佳答案
<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>
应该是
<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>
也就是说,您不应该对 & 符号进行 urlencode。希望这就是打乱您的查询的原因。
此外,the_post_thumbnail()
将显示帖子的特色图片,因此要生成缩略图,您需要确保所有帖子都有特色图片。
关于php - Wordpress 发布缩略图问题(首页上只有 1 个缩略图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12557268/