简体   繁体   English

如何使用wordpress在首页的特殊磁贴中显示3个最新帖子?

[英]How to show 3 most recent posts in a special tiles on home page using wordpress?

I have these tile elements on the top of my homepage: 我的首页上方有这些磁贴元素:

        <div id="tile-holder" class="group">

        <div class="tile1">
            <div class="tile-textbox" style="color: #22284f;">Just Some Title</div>
        </div>
        <div class="tile2">
            <img class="post-image" src="images/sample-large-2.jpg"/>
            <div class="tile-datebox">
                <img src="images/video-icon.png" >
                <p>2013/2/25</p>
                <div class="tile-info"><h1><a href="index2.html">Title 1</a></h1></div>
            </div>
        </div>
        <div class="tile3">
            <img class="post-image" src="images/sample-mid-2.jpg"/>
            <div class="tile-datebox">
                <img src="images/image-icon.png" >
                <p>2013/5/15</p>
                <div class="tile-info"><h1>Title 2</h1></div>
            </div>
        </div>
        <div class="tile4">
            <img class="post-image" src="images/sample-mid-3.jpg"/>
            <div class="tile-datebox">
                <img src="images/text-icon.png" >
                <p>2013/6/17</p>
                <div class="tile-info"><h1>Title 3</h1></div>
            </div>
        </div>
        <div class="tile5">
            <div class="tile-textbox" style="color: #ffffff;">Another Title</div>
        </div>

    </div> <!-- END Tile Holder -->

and I want to show 3 most recent posts in tile 2, 3 and 4; 我想在图块2、3和4中显示3个最新帖子; just the title, date and an image of that that gets the url from custom fields that I defined, I tried using : 只是标题,日期和图像,这些图像从我定义的自定义字段中获取网址,因此我尝试使用:

.
.
.
<?php query_posts("post_per_page=3"); the_post(); ?>
            <div class="tile2">
            <img class="post-image" src="<?php echo get_post_meta($post->ID, 'post_image', true) ?>"/>
            <div class="tile-datebox">
                <img src="<?php echo get_post_meta($post->ID, 'post_icon', true) ?>" >
                <p><?php the_time('F jS, Y') ?></p>
                <div class="tile-info"><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1></div>
            </div>
        </div>
        <div class="tile3">
            <img class="post-image" src="<?php echo get_post_meta($post->ID, 'post_image', true) ?>"/>
            <div class="tile-datebox">
                <img src="<?php echo get_post_meta($post->ID, 'post_icon', true) ?>" >
                <p><?php the_time('F jS, Y') ?></p>
                <div class="tile-info"><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1></div>
            </div>
        </div>
        <div class="tile4">
            <img class="post-image" src="<?php echo get_post_meta($post->ID, 'post_image', true) ?>"/>
            <div class="tile-datebox">
                <img src="<?php echo get_post_meta($post->ID, 'post_icon', true) ?>" >
                <p><?php the_time('F jS, Y') ?></p>
                <div class="tile-info"><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1></div>
            </div>
        </div>
<?php wp_reset_query(); ?> 
.
.
.

but it just gets one post and shows it there, what's wrong? 但是它只有一个帖子并在那里显示,这是怎么回事? what did I missed? 我错过了什么? please help, I'm new in the world of wordpress! 请帮助,我是wordpress领域的新手!

Here is one way to do it. 这是一种方法。 If you're new you should read up on these essential topics: The Loop and WP_Query . 如果您是新手,则应阅读以下重要主题: LoopWP_Query

<?php 

$query = new WP_Query( 'posts_per_page=3' );

// The Loop
if ( $query->have_posts() ) {

    $i = 1;

    while ( $query->have_posts() ) {
        $query->the_post();

        $i++;
        ?>

        <div class="tile<?php echo $i ?>">
            <img class="post-image" src="<?php echo get_post_meta($post->ID, 'post_image', true) ?>"/>
            <div class="tile-datebox">
                <img src="<?php echo get_post_meta($post->ID, 'post_icon', true) ?>" >
                <p><?php the_time('F jS, Y') ?></p>
                <div class="tile-info"><h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1></div>
            </div>
        </div>
<?php


    }
} else {
    // no posts found
}

/* Restore original Post Data */
wp_reset_postdata();
<?php $args = array(
    'numberposts' => 3,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true );

    $recent_posts = wp_get_recent_posts( $args, ARRAY_A );


   //write loop here
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要在我的Codeigniter网站上显示最近的两个wordpress帖子 - I need to show recent two wordpress posts in my codeigniter site at home page 如何在Wordpress中获取和显示主页上标签的特定帖子 - How to fetch and show particular posts for a tag on home page in wordpress WordPress-主页和内页都必须列出最近的帖子:如何在主页中链接内页? - Wordpress - Homepage and inner page both must list recent posts: how to link the inner page in the home? 在Wordpress中输出3个最新帖子 - Output 3 most recent posts in Wordpress 如何仅显示WordPress中自定义分类法的最新类别的帖子 - How to show only the posts from the most recent category of a custom taxonomy in WordPress 仅在单击链接时如何显示WordPress博客主页中的最新帖子 - How to Display recent Posts in WordPress blog home page only when a link is clicked WordPress-“ The Loop”显示所有帖子,而不是发布首页标题 - WordPress - 'The Loop' to show all posts, instead posts the title of the home page 在自定义的最新帖子页面上显示下一页/上一页按钮 - Show next/previous page buttons on custom recent posts page Wordpress 使用自定义Wordpress查询来调用5个最新帖子 - Using a custom Wordpress query to call 5 most recent posts 按最近的评论排序 Wordpress 帖子 - Ordering Wordpress posts by most recent comment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM