简体   繁体   中英

how to get the posts from my index page to someother pages(like blog) in WordPress

i am beginner to WordPress, i have created the index.php it automatically shows my posts.. but i wanna posts to show also in another php file like blog.php .. how can i retrieve the same posts which is shown in index.php .........

The scenario is, i am developing theme for http://themeforest.net show that i wanna make some features in my blog page like without sidebar, left sidebar, right sidebar ... but my home(index.php) contains posts.. whenever i starts new page with same coding(like blog.php), it doesn't show the index.php 's posts..

This sample piece of code retrieves 3 posts from categpry id 4

<?php
    $args = array( 'numberposts' => 3, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 4 );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post);
    $a= get_the_date();
    ?>

    <h1><?php the_title(); ?></h1>
    <p><?php the_content(); ?></p>

    <?php endforeach; ?>

请参阅WordPress文档http://codex.wordpress.org/The_Loop,其中包含如何显示帖子包含或排除特定类别等内容的其他示例。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM