How to Insert PHP between shortcodes for Tabs [tab

2019-06-12 19:29发布

I am looking to get some help in how to insert my php between my 2 tabs. I am using wordpress and trying to modify a template so that I can have 2 tabs on my page with dynamic content from two other php pages.

I get 2 tabs but the content does not appear in the tabs, but instead above them. I misut be doing something wrong with the code below, but I have no idea what!

My code is as follows:

<?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]');

?>

any help much appreciated!

1条回答
Luminary・发光体
2楼-- · 2019-06-12 20:36

get_template_part just spits out the content then and there, where the function is expecting a big long string.

You'll have to capture the output and put it in manually.

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]');
查看更多
登录 后发表回答