2014-01-11 72 views
1

我有一個名爲Dashboard的頁面,並希望在Dashboard頁面上顯示說A頁面和B頁面的內容。我可以用下面的代碼實現這一點,但我只想顯示部分內容的A和B像片段。如何以與A頁和B頁上顯示的樣式完全相同的樣式顯示?如何在wordpress中顯示另一頁上的部分內容?

function show_post($path) { 
$post = get_page_by_path($path); 
$content = apply_filters('the_content', $post->post_content); 
echo $content; 
} 

<?php show_post('pageA'); // Shows the content of the "PageA" page. ?> 
<?php show_post('pageB'); // Shows the content of the "PageB" page. ?> 

頁A顯示了這種代碼的內容:

<ul class="leftlist"> 
     <?php 
     while ($loop->have_posts()) : $loop->the_post(); 
     ?> 
     <li class="todo" id="<?php echo get_the_ID();?>" itemage="<?php echo get_post_meta(get_the_ID(),'_todotime',true)?>"><a href="javascript:;" 
     <?php if($all_meta_for_user[get_the_ID()][0]){    
     ?> 
     class="strike" 
     <?php 
     } 
     ?> 
     >   
     <?php if($all_meta_for_user[get_the_ID()][0]){?> 
      <span class="check_box cb"></span> 
      <?php }else{?> 
     <span class="uncheck_box cb"></span> 
     <?php }?> 
     <p><?php the_title(); ?></p></a>   
     <?php 
     endwhile; 
     ?>    
     </ul> 

在此先感謝

+0

你只是想借此從整個a或b頁面的一部分。它將顯示在儀表板頁面中。對 ? –

+0

是的,只是其中的一部分而不是整個內容 – user2798091

+0

好吧,讓我輸入一個鼻子 –

回答

0

,你可以很容易地通過郵局爲此創造2個職位假設A和B就會產生ID的像20,22 ...並在您的網頁中使用此代碼作爲網頁A:

<?php $cquery = new WP_Query('cat=20'); $i=1; ?> 
     <?php if($cquery->have_posts()): while($cquery->have_posts()): $cquery->the_post(); 
     <?php the_post_thumbnail(); ?> 
     <?php the_content(); ?> 
     <?php $i++; endwhile; endif; endif; ?> 

以及類似的後B有ID 22.

+0

謝謝..但不會顯示postA....我只想顯示部分內容的整個內容。例如,我有postA上的檢查清單。只想顯示3個檢查清單而不是全部檢查清單。 – user2798091

+0

所以,你可以將你的內容分成兩部分。 –

+0

<?php $ cont = apply_filters('the_content',$ page-> post_content); $ arr = explode(「。」,$ content); $ first = $ arr [0]; echo $ first; ?> –

0

我不是最極端的PHP編碼器。但我正在嘗試。 以下是您可以使用php explode完成的代碼。

在你的頁面A或B只是放一個標識符爆炸。 像這樣:

Here is the first of the contents of the page. 
<!--start--> 
From this part you want to show something 
<!--stop--> 
Here is the rest of the contents 

然後你的函數是這樣的:

function show_post($path) { 
$post = get_page_by_path($path); 
$content = apply_filters('the_content', $post->post_content); 
$explode=explode('<!--start-->',$content); 
$explode=explode('<!--stop-->',$explode[1]); 
echo $explode[0]; 
} 
+0

謝謝.. pageA上的內容顯示動態內容,所以使用爆炸方法將無法正常工作。查看更新的問題。 – user2798091

相關問題