如何在选项卡的短代码之间插入PHP[tab]


How to Insert PHP between shortcodes for Tabs [tab]

我想获得一些帮助,了解如何在我的两个选项卡之间插入我的php。我正在使用wordpress并试图修改一个模板,以便在我的页面上有两个选项卡,其中包含来自另外两个php页面的动态内容。

我有两个选项卡,但内容不显示在选项卡中,而是显示在选项卡上方。我没有用下面的代码做错事,但我不知道是什么!

我的代码如下:

<?php
echo do_shortcode('[tabs style="boxed"]
[tab title="First Tab"]' .get_template_part("includes/categories-panel"). '[/tab]
[tab title="Second Tab"]'. get_template_part('includes/home-map-panel')  .'[/tab]
[tab title="Third Tab"] Tab 3 Content here [/tab]
[tab title="Fourth Tab"] Tab 4 Content here [/tab]
[/tabs]');
?>

非常感谢您的帮助!

get_template_part只是当场吐出内容,函数需要一个大的长字符串。

您必须捕获输出并手动将其放入。

ob_start();
get_template_part("includes/categories-panel");
$cats = ob_get_clean();
ob_start();
get_template_part('includes/home-map-panel');
$home = ob_get_clean();
echo do_shortcode('[tabs style="boxed"]
[tab title="First Tab"]' .$cats. '[/tab]
[tab title="Second Tab"]'. $home  .'[/tab]
[tab title="Third Tab"] Tab 3 Content here [/tab]
[tab title="Fourth Tab"] Tab 4 Content here [/tab]
[/tabs]');