php - Wordpress 发布缩略图问题(首页上只有 1 个缩略图)

标签 php css wordpress loops content-management-system

我在 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&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/

我想显示所有与第一个相似的帖子。

谢谢!

最佳答案

<?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() 将显示帖子的特色图片,因此要生成缩略图,您需要确保所有帖子都有特色图片。

关于php - Wordpress 发布缩略图问题(首页上只有 1 个缩略图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12557268/

相关文章:

wordpress - 使用 wp_insert_post() 创建一个新页面

javascript - 用另一个 div 的溢出内容填充 div

php - 如何格式化系统函数PHP的输出?

php - WooCommerce REST API : Only returns 10 categories

php - Doctrine 批量插入 - 实体管理器清除

html - Chrome 中的 CSS3 过渡故障

javascript - 仅当输入字段中有内容时才使用 javascript 分配类

html - 如何在 3 float :left divs 中堆放中心 div

php - 我需要检查我的数据库以查看用户名或电子邮件是否已在使用中

php - 用 + 增加一个计数器并将值存储到数据库