2011-01-27 227 views
4

我爲wordpress構建了一個非常獨特和JavaScript密集的主題,現在短代碼不起作用。我沒有安裝任何插件,所以不是這樣。我從使用簡碼所需的wordpress模板文件中刪除了什麼(即:[gallery])。WordPress短代碼不能正常工作

我瞭解如何製作簡碼,但WP如何將您的帖子替換爲「[gallery]」,當它將它吐出顯示時?

編輯: 這裏是我目前正在工作:

$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A); 
    $i = 1; 
    foreach ($pagepull as $single_page){ 
    echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">"; 
     echo $single_page['post_content']; 
$i++; 
// more code that is irrelevant... 
// more code that is irrelevant... 
// more code that is irrelevant... 
    } 
+0

看看我的答案在下面! – keatch 2011-01-27 14:07:00

+1

簡短回答:您正在使用原始內容($ single_page ['post_content']),而不是過濾後的內容:apply the_content filter。 echo apply_filters('the_content',$ single_page ['post_content']); – keatch 2011-01-27 15:30:19

回答

11

好吧,試試這個

$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A); 
    $i = 1; 
    foreach ($pagepull as $single_page){ 
    echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">"; 
     echo apply_filters('the_content',$single_page['post_content']); 
$i++; 

WordPress的把你的內容和應用過濾器了。您必須註冊一個過濾器並解析您的內容。

如果您的主題不顯示您的簡碼,可能會輸出郵件的內容而不讓Wordpress過濾它。

爲帖子調用函數get_the_content(),不會爲短代碼運行過濾器(如果有的話)。

若要申請

<?php apply_filters('the_content',get_the_content($more_link_text, $stripteaser, $more_file)) ?> 

編號:http://codex.wordpress.org/Function_Reference/get_the_content

注:很多插件與實現的簡寄存器的內容過濾器!

1

使用這個,如果你想有一個變量裏面的內容:

ob_start(); 
the_content(); 
$content = ob_get_clean(); 

現在你可以只是做回聲$內容;或使用正則表達式或任何你想使內容看起來像你想要的。

0

請在功能開始使用

ob_start(); 

和關閉該功能之前,使用

return ob_get_clean(); 

希望這會對你有幫助。

乾杯

1

我有同樣的問題。

短代碼取決於WP循環,但這是一個不同的問題。長話短說,我在應該顯示簡碼的頁面上添加了the_post();(例如articles.php)。

此外,請確保您使用the_content()爲了顯示文本(使用$post->post_data,例如不會顯示您的簡碼)。