0

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

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

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

4

2 回答 2

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; ?>
于 2013-04-25T15:22:28.750 回答
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

于 2013-04-25T11:39:39.307 回答