P.S. Forgot to mention that you would want to use the classes in the above code to style your output in the Theme Panel -> Custom CSS part.
Thanks for coming back. I am sorry for a late reply. I was trying to implement the code in the new post type “Phones” which i created using a pluging “CPT UI”. But each time i enabled the custom post type “single-phones.php” It gives me a blank page.
Here is the template i am using for custom post type “phones”.
<?php
/* ----------------------------------------------------------------------------
the page template
*/
get_header();
switch ($loop_sidebar_position) {
case 'sidebar_left':
echo td_page_generator::wrap_start();
?>
<div class="span4 column_container" role="complementary" itemscope="itemscope" itemtype="<?php echo td_global::$http_or_https?>://schema.org/WPSideBar">
<?php get_sidebar(); ?>
</div>
<div class="span8 column_container td-no-pagination" role="main" itemscope="itemscope" itemprop="mainContentOfPage" itemtype="<?php echo td_global::$http_or_https?>://schema.org/CreativeWork">
<?php
// Update this list using the same format for all the field names you want
$field_names = ['2g_network', '3g_network'];
// Set up tabs
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Set up features tab
$to_echo .= '[vc_tab title="Features" tab_id="features"]';
// Begin a list
$to_echo .= '<ul class="features_list">';
// Loop through the fields
foreach ($field_names as $field_name) {
$data = get_field_object($field_name);
// Check if we have a value and set to a default if not
if ($data['value']) {
$value = $data['value'];
} else {
$value = 'No information on record.';
}
$to_echo .= '<li>' . '<span class="features_label">' . $data["label"] . ': </span>';
$to_echo .= '<span class="features_value">' . $value . '</span></li>';
}
// Close the list
$to_echo .= '</ul>';
// Close the tab
$to_echo .= '[/vc_tab]';
// Close the tab group etc.
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Output
echo $to_echo;
?>
</div>
<?php
echo td_page_generator::wrap_end();
break;
case 'no_sidebar':
echo td_page_generator::wrap_start();
?>
<div class="span12 column_container td-no-pagination" role="main" itemscope="itemscope" itemprop="mainContentOfPage" itemtype="<?php echo td_global::$http_or_https?>://schema.org/CreativeWork">
<?php
// Update this list using the same format for all the field names you want
$field_names = ['2g_network', '3g_network'];
// Set up tabs
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Set up features tab
$to_echo .= '[vc_tab title="Features" tab_id="features"]';
// Begin a list
$to_echo .= '<ul class="features_list">';
// Loop through the fields
foreach ($field_names as $field_name) {
$data = get_field_object($field_name);
// Check if we have a value and set to a default if not
if ($data['value']) {
$value = $data['value'];
} else {
$value = 'No information on record.';
}
$to_echo .= '<li>' . '<span class="features_label">' . $data["label"] . ': </span>';
$to_echo .= '<span class="features_value">' . $value . '</span></li>';
}
// Close the list
$to_echo .= '</ul>';
// Close the tab
$to_echo .= '[/vc_tab]';
// Close the tab group etc.
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Output
echo $to_echo;
?>
</div>
<?php
echo td_page_generator::wrap_end();
break;
default:
echo td_page_generator::wrap_start();
?>
<div class="span8 column_container td-no-pagination" role="main" itemscope="itemscope" itemprop="mainContentOfPage" itemtype="<?php echo td_global::$http_or_https?>://schema.org/CreativeWork">
<?php
// Update this list using the same format for all the field names you want
$field_names = ['2g_network', '3g_network'];
// Set up tabs
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Set up features tab
$to_echo .= '[vc_tab title="Features" tab_id="features"]';
// Begin a list
$to_echo .= '<ul class="features_list">';
// Loop through the fields
foreach ($field_names as $field_name) {
$data = get_field_object($field_name);
// Check if we have a value and set to a default if not
if ($data['value']) {
$value = $data['value'];
} else {
$value = 'No information on record.';
}
$to_echo .= '<li>' . '<span class="features_label">' . $data["label"] . ': </span>';
$to_echo .= '<span class="features_value">' . $value . '</span></li>';
}
// Close the list
$to_echo .= '</ul>';
// Close the tab
$to_echo .= '[/vc_tab]';
// Close the tab group etc.
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Output
echo $to_echo;
?>
</div>
<div class="span4 column_container" role="complementary" itemscope="itemscope" itemtype="<?php echo td_global::$http_or_https?>://schema.org/WPSideBar">
<?php get_sidebar(); ?>
</div>
<?php
echo td_page_generator::wrap_end();
break;
}
get_footer();
?>
I think i am making some nonsense mistake in the above template. That’s why i am getting a blank page. Tried a lot. Thanks 🙂
For CSS part. that’s ofcourse not an issue. I will do that. One of my friends knows CSS quite well.
Thanks
Hmm… I’ve never done this myself (create a new post template). Your blank page might have something to do with the content being loaded partly in single_template_#.php and partly in loop-single-#.php for each of these templates. Do you have all the parts you need?
P.S. If you’re going to repeat that code for each sidebar case, you can at least define a function in the same file. That is to say, have this at the top, in PHP tags:
function my_features_fields() { // No parameter because $post is still active
// Update this list using the same format for all the field names you want
$field_names = ['2g_network', '3g_network'];
// Set up tabs
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Set up features tab
$to_echo .= '[vc_tab title="Features" tab_id="features"]';
// Begin a list
$to_echo .= '<ul class="features_list">';
// Loop through the fields
foreach ($field_names as $field_name) {
$data = get_field_object($field_name);
// Check if we have a value and set to a default if not
if ($data['value']) {
$value = $data['value'];
} else {
$value = 'No information on record.';
}
$to_echo .= '<li>' . '<span class="features_label">' . $data["label"] . ': </span>';
$to_echo .= '<span class="features_value">' . $value . '</span></li>';
}
// Close the list
$to_echo .= '</ul>';
// Close the tab
$to_echo .= '[/vc_tab]';
// Close the tab group etc.
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Output
return $to_echo;
}
And then just have this one line wherever you want to place your tabs:
<?php echo my_features_fields(); ?>
Good luck getting the rest working! I’ll stop checking this thread shortly, but it’s been good.
Sorry for late late reply. Actually i was working really hard to achieve all this. First i encountered a problem in creating a CPT and then several other issues. However, I managed to setup this now. Thanks again. I will be back in a day or two and then i will show you my page. It’s still under construction but now is in working condition. Once again, Thanks alot. It will never be possible with a wonderful support from you. 🙂