帖子预览/缩略图显示不正确-链接到“主页”而不是帖子?

时间:2012-05-21 作者:user1255049

Live site

在登录页的下半部分,我希望有三篇博客文章预览-只有三篇最新文章的标题和缩略图。我正在使用以下代码:

<?php get_header(); ?>

<div id="container">
    <div id="landing">
        <div id="intro">
            <h1>Hi, I\'m Dylan Elchami-<br />a health and fitness enthusiast with a passion for inspiring.</h1>
            <p>My interests are vast and ever changing, but my virtues remain true. I love to motivate, create, make people healthier, stronger, sexier, and flat out better all while building great, unmitigated relationships along the way. Please roam my site and enjoy all the information I post for you, and if you have a question please don\'t hesitate to contact me- it\'s your way of giving back for all the free information because helping you is what makes me feel AWESOME.</p>
        </div><!-- end intro -->

        <div id="stay-in-touch">
            <p>Stay in touch-</p>
            <ul>
                <li><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/facebook.png" alt="Like on Facebook" /></a></li>
                <li><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/twitter.png" alt="Follow on Twitter" /></a></li>
                <li><a href="#"><img src="<?php echo get_template_directory_uri(); ?>/img/linkedin.png" alt="Connect on LinkedIn" /></a></li>
            </ul>
        </div><!-- end stay-in-touch -->

        <div id="preview">
            <div id="preview-item">
                <div id="preview-headline">
                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
                </div><!-- end preview-headline -->
                <div id="preview-thumbnail">
                    <?php $my_query = new WP_Query( array( \'posts_per_page\' => 3, \'nopaging\' => true ) ); while ( $my_query->have_posts() ) : ( $my_query->the_post() ); ?>
                    <?php endwhile; ?> 
                </div><!-- end preview-thumbnail -->
            </div><!-- end preview-item --> 
        </div><!-- end preview-->
    </div><!-- end landing -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>
我有add_theme_support( \'post-thumbnails\' ); 在函数中。php

正如你在网站上看到的,预览的链接上写着“主页”,没有缩略图。如何将最近的3篇帖子显示为预览,并将它们实际链接到帖子(而不是主页)?

1 个回复
最合适的回答,由SO网友:SickHippie 整理而成

听起来你需要在主页上进行第二次循环才能调用最近的3篇帖子。尝试以下操作:

// Main home page content here

<?php $my_query = new WP_Query( array( \'posts_per_page\' => 3, \'nopaging\' => true ) );
while ( $my_query->have_posts() ) : ( $my_query->the_post() ); ?>
<div id="preview">
    <div id="preview-item">
        <div id="preview-headline">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
    </div><!-- end preview-headline -->
    <div id="preview-thumbnail">
        <?php the_post_thumbnail( array(120,102) ); ?> 
    </div><!-- end preview-thumbnail -->
    </div><!-- end preview-item --> 
</div><!-- end preview-->
<?php endwhile; ?>

// Closing Home page content here

结束

相关推荐

Custom post type permalinks

我有一个名为“数字”的自定义帖子类型,我想实现URL的“帖子”如下http://website.com/post-name 而不是http://website.com/number/post-name.我试图将register\\u post\\u type中的“rewrite”参数设置为:\'rewrite\' => array( \'slug\' => \'\', \'with_front\' => false ), 但它没有起作用。即使我保存了永久链接设置以刷新它。(我将永久链接设