如何将我的索引页面中的帖子发送到WordPress中的其他一些页面(如博客)

时间:2014-02-03 12:08:50

标签: php wordpress indexing

我是WordPress的初学者,我已经创建了 index.php 它会自动显示我的帖子..但是我想在另一个php文件中显示如< strong> blog.php ..如何检索 index.php中显示的相同帖子 .........

情节是,我正在开发http://themeforest.net的主题,表示我想在我的博客页面中创建一些功能,如,没有侧边栏,左侧边栏,右侧边栏 ...但是我的家(index.php)包含帖子..每当我开始使用相同编码的新页面(如blog.php)时,它都不会显示index.php的帖子..

2 个答案:

答案 0 :(得分:1)

此示例代码从类别ID 4

中检索3个帖子
<?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; ?>

答案 1 :(得分:0)

参阅WordPress文档http://codex.wordpress.org/The_Loop 它包含不同的示例,如何显示帖子包含或排除特定类别的帖子等。