2016-07-09 31 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