2013-04-25 50 views
0

我有我這樣的邏輯,但我不能在我的wordpress上實現我是這個平臺的新手。從不同的slu get中獲得不同的頁面

  • 會從不同的蛞蝓不同的頁面
  • 顯示頁面標題,並從slug1
  • 顯示內容的頁面標題,並從slug2
  • 顯示頁面標題,並從slug3
  • 內容的內容

總而言之,它們將顯示在單個頁面上。

+0

正如你所說,你是這個平臺的新手,你有沒有得到你的術語是正確的?你的意思是''頁面''還是你想說''帖子「'? – krembo99 2013-04-25 02:28:59

+0

hmmmn ..這些是網頁,將顯示在一個頁面.. 得到這些網頁..我認爲他們的slu to是關鍵。也許我會首先聲明slu .. ......在wordpress上怎麼做? – 2013-04-25 02:42:37

+0

slu are通常是根據你的[固定鏈接](http://codex.wordpress.org/Settings_Permalinks_Screen)的結構來自動標題, – 2013-04-25 03:08:23

回答

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

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; ?>