【问题标题】:how to get the posts from my index page to someother pages(like blog) in WordPress如何将帖子从我的索引页面获取到 WordPress 中的其他页面(如博客)
【发布时间】:2014-02-26 22:06:18
【问题描述】:

我是 WordPress 的初学者,我创建了 index.php 它会自动显示我的帖子.. 但我希望帖子也显示在另一个 php 文件中,例如 blog.php.. 我怎样才能检索到 index.php 中显示的相同帖子............

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

【问题讨论】:

    标签: php wordpress indexing


    【解决方案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; ?>
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 2012-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多