2015-04-06 122 views
0

我正在尋找一種方法從我的某個頁面獲取the_content並將其顯示在另一個頁面中。最好使用頁面塊/標題。從一個頁面獲取the_content並在另一個頁面中顯示(Wordpress)

我發現了一個代碼,似乎工作,但它使用頁面ID。有沒有辦法修改這段代碼,以便它使用頁slu /標題?

<div> 
    <?php 
     $id = 238; 
     $p = get_page($id); 
     echo apply_filters('the_content', $p->post_content); 
    ?> 
</div> 

謝謝。

+0

的名字你的意思是網頁塊或標題?檢查[get_page_by_title](https://codex.wordpress.org/Function_Reference/get_page_by_title)out – d79

+0

它可以是slu or或標題@ d79 – chrisbedoya

回答

0

按標題:

<div> 
    <?php 
     $page = get_page_by_title('Page Title'); 
     if($page) { 
      echo apply_filters('the_content', $page->post_content); 
     } 
    ?> 
</div> 

通過毛坯:

<div> 
    <?php 
     $page = get_page_by_path('page-title'); 
     if($page) { 
      echo apply_filters('the_content', $page->post_content); 
     } 
    ?> 
</div> 
+0

謝謝你的幫助! – chrisbedoya

相關問題