Php WordPress短代码的大型HTML呈现/输出

Php WordPress短代码的大型HTML呈现/输出,php,wordpress,Php,Wordpress,我正在制作自定义可湿性粉剂插件将有短代码。此短代码将具有类别slug属性,根据类别slug,它将获取帖子并将前5个帖子及其特征图像显示到旋转木马或自定义滑块中。输出将有一个大的HTML片段 这里是最基本的代码 function posts_from_category( $atts ) { ob_start(); global $posts; $args = array('category_name' => $atts['category_slug'] ); $

我正在制作自定义可湿性粉剂插件将有短代码。此短代码将具有类别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

get_template_部分(文件的路径)(例如:get_template_文件('myslide','template');您应该拥有名为myslide-template.phpHow的模板文件。我是否将$posts传递到此文件?这与要求相同您只需使用:include(查找_template('your-template-name.php'));模板中提供了函数的所有变量。有关更多信息:nops man it not working更新代码以查看