2016-07-09 34 views
0

我有一個簡短代碼,它通過類別名稱查看通過Worpress帖子並將它們顯示在前端。如果該類別中沒有帖子,則用戶可以寫入「無帖子可用」消息。如何將Wordpress wpautop包裝到CSS操作類的容器中

wpautop用<p>...</p>包裝消息。

我想給這個樣式設計<p>。我不能簡單地將CSS添加到段落標記中。這並不簡單。樣式只需要與此消息隔離。那麼,有人可以幫助我修改下面的代碼,以包裝一個div容器與一個類的回報?

感謝

$listing = new WP_Query(apply_filters('display_posts_shortcode_args', $args, $original_atts)); 
if (! $listing->have_posts()) { 
    /** 
    * Filter content to display if no posts match the current query. 
    * 
    */ 
    return apply_filters('display_posts_shortcode_no_results', wpautop($no_posts_message)); 
} 

回答

-1

可以通過爲wpautop創造其他功能做()。

wpautop()函數在wp-includes/formatting.php中編碼,將函數複製到模板目錄下的functions.php並編輯。

1)改變功能的名稱,並添加一個新的參數爲類名,

function wpautop($pee, $br = true) { 

function wpautopNew($pee, $className = null, $br = true) { 

2)搜索和功能改變這種循環

// Rebuild the content as a string, wrapping every bit with a <p>. 
foreach ($pees as $tinkle) { 
    $pee .= '<p>'. trim($tinkle, "\n") . "</p>\n"; 
} 

as this

// Rebuild the content as a string, wrapping every bit with a <p>. 
foreach ($pees as $tinkle) { 
    $pee .= '<div class="'.$className.'"><p>' . trim($tinkle, "\n") . "</p></div>\n"; 
} 

3)使用新函數並給出類名作爲第二個參數。下面的示例

wpautopNew($no_posts_message, 'yourclassname') 
+0

儘管此代碼可以解決這個問題,它並沒有回答這是包裝在一個容器中輸出的結果使用CSS操縱的問題。 – HiDeo

0

使用:對

$page_cont  = wpautop('YOUR_CONTENT'); 
$added_class = str_replace('<p>', '<p class="text-center">', $page_cont); 
echo $added_class; 
+1

請與您的答案一起發佈一些解釋。感謝您的貢獻! – Terrance00