【问题标题】:Wordpress Post Thumbnail Issue (Only 1 thumbnail on frontpage)Wordpress 帖子缩略图问题(首页上只有 1 个缩略图)
【发布时间】:2012-09-15 10:54:35
【问题描述】:

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

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

谢谢!

【问题讨论】:

  • 对不起,我对正在发生的事情和未发生的事情感到困惑。我只看到第一个链接上列出了 1 个帖子,其他 2 个链接看起来一样。什么是对的,什么是错的?
  • 啊,等等,好的,第一个链接上应该有 3 张图片?前两个的链接是空的,是吗?这些文章是否有特色图片,或者图片只是插入到页面中?
  • @zenkaty - 是的,你没看错。这只是所有帖子上的插入图像。没有推荐。

标签: php css wordpress loops content-management-system


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

【讨论】:

  • 啊!我没有注意到我在第一篇文章中设置了特色图片。刚刚在所有帖子上添加了特色图片,就像魅力一样。非常感谢你的帮助。 :)
  • 帖子有特色图片吗?他们需要让 the_post_thumbnail() 工作。
猜你喜欢
  • 2011-09-04
  • 2015-07-19
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-17
  • 1970-01-01
  • 2017-08-02
  • 2014-04-15
相关资源
最近更新 更多