WordPress短代码的大型HTML渲染/输出

时间:2017-06-10 22:12:01

标签: php wordpress

我正在制作具有短代码的自定义WP插件。这个短代码将具有类别slug的属性,并且根据类别slug,它将获取帖子并将其中的前5个显示为其特色图像到旋转木马或自定义滑块中。输出将有一个大的HTML片段。

这里是非常基本的代码

function posts_from_category( $atts ) {
   ob_start();
    global $posts;
    $args = array('category_name' => $atts['category_slug'] );
    $posts = get_posts( $args );
   //Here either I want to include a php file as template and pass the $posts some how which I am not able to do or make string concatenated HTML fragment or heredoc.
   return ob_get_clean();
}


add_shortcode("posts_from_category", 'posts_from_category');

我想用它作为

[posts_from_category category_slug="services"]

请帮助我如何完成它,因为我是php和WP的新手。

0 个答案:

没有答案