How to Insert PHP between shortcodes for Tabs [tab]

无人久伴 提交于 2019-12-23 04:35:33

问题


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:


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


来源:https://stackoverflow.com/questions/11397441/how-to-insert-php-between-shortcodes-for-tabs-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!