从不同的slu have中获取不同的页面

时间:2013-04-25 02:21:23

标签: wordpress-theming wordpress

我有这样的逻辑,但我不能在我的wordpress上实现它我是这个平台的新手。

  • 从不同的slugs中获取不同的页面
  • 显示页面标题和来自slug1的内容
  • 显示页面标题和来自slug2的内容
  • 显示页面标题和来自slug3的内容

总而言之,它们将显示在一个页面上。

2 个答案:

答案 0 :(得分:0)

从ID而不是页面获取页面会更好,即使它们被称为“永久链接”,您仍然可以更改它们,然后您还必须更新代码,这很痛苦当然。

我建议你为你的页面创建一个模板,当你完成后,你可以在模板中查询多个帖子/页面。

您可以创建如下模板:

<?php
/*
Template Name: Snarfer
*/
?>

之后,您可以查询不同的帖子,如下所示:

$query = new WP_Query( 'page_id=7' ); //this will get the page with teh ID 7

while ( $query -> have_posts() ) : $query -> the_post();
    //query the page data here like the_content(), the_title();
endwhile;

如果您想要查询所有查询页面的相同样式,那么您最好使用post__in变量进行查询。点击此处了解有关不同选项的更多信息:https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

在此处详细了解自定义模板:http://codex.wordpress.org/Theme_Development#Custom_Page_Templates

答案 1 :(得分:0)

我刚才意识到我没有使用正确的方法。我通过显示由他们的ID给出的3个帖子做得恰到好处

<?php
    $postslist  = get_posts('include=120,122,124&orderby=ID&order=ASC');
                    foreach ($postslist as $post) :  setup_postdata($post); ?>

     <h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
                    <p><?php the_excerpt(); ?></p>

                  <?php endforeach; ?>