Nested Tabs with Repeater - Advance Custom Fields Wordpress - php

I want to make some tabs with Wordpress Using the Advance Custom Field Plug-in with the Repeater Add-On.
This is my actual code:
<?php
if( have_rows('menu_sections') ): ?>
<ul class="nav nav-tabs" id="" role="tablist">
<?php $i=0; while ( have_rows('menu_sections') ) : the_row(); ?>
<?php
$string = sanitize_title( get_sub_field('section_title') );
?>
<li role="presentation" <?php if ($i==0) { ?>class="active"<?php } ?> >
<a role="tab" data-toggle="tab"><?php the_sub_field('section_title'); ?></a>
</li>
<?php $i++; endwhile; ?>
</ul>
<div class="tab-content">
<?php $i=0; while ( have_rows('menu_sections') ) : the_row(); ?>
<?php
$string = sanitize_title( get_sub_field('section_title') );
?>
<div role="tabpanel" class="tab-pane text-left fade <?php if ($i==0) { ?>in active<?php } ?>" id="<?php echo $string; ?>">
<?php
while (have_rows('section_items')) {
the_row();
// Display each item as a list
?>
<ul>
<li class="list-unstyled"><?php the_sub_field('dish_name'); ?></li>
<li class="list-unstyled"><?php the_sub_field('dish_description'); ?></li>
<li class="list-unstyled"><?php the_sub_field('dish_price'); ?></li>
</ul>
<?php
} // end while have rows section_items
?>
</div>
<?php $i++; endwhile; ?>
</div>
<?php endif; ?>
This Actual code displays this:
Now if i select another tab it won't change the card info as you can see in the next image:
Im using a Bootstrap Tabs with a CDN
This is what the Gooogle console display:
So I tried many different ways but no success at all.
I do know how to make them without a nested repeater, and with this case I don't know why it dosen't work. I read some other posts but no having much success either. So I think that if it dosen't show is something with css??
I will appreaciate the help.
Regards!

Try changing
<li role="presentation" <?php if ($i==0) { ?>class="active"<?php } ?> >
<a role="tab" data-toggle="tab"><?php the_sub_field('section_title'); ?></a>
</li>
to
<li role="presentation" <?php if ($i==0) { ?>class="active"<?php } ?> >
<a role="tab" data-toggle="tab" href="#tab-<?php echo $i; ?>"><?php the_sub_field('section_title'); ?></a>
</li>
and
<div role="tabpanel" class="tab-pane text-left fade <?php if ($i==0) { ?>in active<?php } ?>" id="<?php echo $string; ?>">
to
<div role="tabpanel" class="tab-pane text-left fade <?php if ($i==0) { ?>in active<?php } ?>" id="tab-<?php echo $i; ?>">
I hope it will solve the issue. You are assigning a section title as id to tab-pane, which might contain space as well. It's always recommended to use id without spaces.

Related

How to fix Wordpress Dropdown Menu of All Terms in Custom Taxonomy that don't show list?

I am trying to fix a problem found in this project: http://farmaciassaopaulo-com.umbler.net/.
Below the banner are the 'categories' and 'tags' buttons that should list the custom wordpress categories.
But the drop down menu does not display the listing.
Using the browser console we can see the listing,
but for some coding failure I couldn't figure out where the error comes from.
Could any Wordpress expert guide me?
Best regards.
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">CATEGORIAS
<span class="caret"></span>
</a>
<ul class="dropdown-menu" style="width: 100%;">
<?php
$args = array('parent' => 0);
$terms = get_terms('categorias', $args);
foreach( $terms as $term ):
$children = get_terms( 'categorias', array('parent' => $term->term_id));
?>
<li class="lista-categoria font-museo-sans-300 dropdown-submenu">
<a href="<?php echo get_category_link( $term->term_id ) ?>">
<?php echo $term->name; ?>
<?php if ($children) { ?>
<span class="caret-right"></span>
<?php } ?>
</a>
<?php if ($children) { ?>
<ul class="dropdown-menu">
<?php foreach( $children as $childrens ): ?>
<li>
<a tabindex="-1" href="<?php echo get_category_link( $childrens->term_id ) ?>">
<?php echo $childrens->name;?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
</li>
<?php endforeach; ?>
</ul>
</li>

Is there a way to repeat a li class 'x' amount of times?

I am hopeful there is a way to greatly improve my bit of code.
I have a li class which I need to repeat 'x' amount of times based on a php variable.
I am getting around this at the moment by using a nested IF statement but surely there is a cleaner way?
if ($pTotal == 5) {?>
<div class="point-container">
<div class="row">
<ul class="score">
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
</ul>
</div>
</div>
<?php } elseif ($pTotal == 6) { ?>
<div class="point-container">
<div class="row">
<ul class="score">
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
<li class='points'></li>
</ul>
</div>
</div>
<?php } elseif ($pTotal == 7) { ?>
You can easily use str_repeat() to repeat the same chunk of text for a specific number of times...
$div = '<div class="point-container">
<div class="row">
<ul class="score">';
$div .= str_repeat("<li class='points'></li>", $pTotal);
$div .="</ul></div></div>";
echo $div;
<?php function printLi(int $pTotal) { ?>
<div class="point-container">
<div class="row">
<ul class="score">
<?php for ($i = 0; $i < $pTotal; $i++): ?>
<li class='points'></li>
<?php endfor; ?>
</ul>
</div>
</div>
<?php } ?>
<?php printLi($pTotal);

include div in foreach just in some condition

I have some navbar with menu and submenu, I want to appear some <div> in that menu to appear the submenu just if this menu has submenu items
The div that I want to appear are div1, div2, div3, see comments and in this condition : <?php if ($men["titre"] == $sub["parentmenu"]) : ?>
I can't put them in this foreach : <?php foreach($submenu as $sub) :?> because I need that three div just ones for all the submenu <li>
Exemple of one menu who have submenus:
<li class="Menu1">
<a class="header-menu " href="#">Menu1 title</a> //Menu1
<div class="mobile-header-nav-submenu-container"> //div 1
<ul class="mobile-header-nav-submenu"> //div 2
<div class="mobile-header-nav-submenu-li-container"> //div3
<li class="submenu1">
<a class="" href="#">Submenu1</a>
</li>
<li class="submenu2">
<a class="" href="#">Submenu2</a>
</li>
<li class="submenu3">
<a class="" href="#">Submenu3</a>
</li>
</div>
</ul>
</div>
</li>
My code:
<div class="menu>
<?php foreach ($menu as $men): ?>
<li class="<?php echo $men["titre"]?>">
<a class="header-menu <?php echo $men["lien"]?>" href="<?php if($men["lien"]){echo $baseUrl.$men["lien"];}else{echo '#';}?>"><?php echo $men["titre"]?></a>
<div class="mobile-header-nav-submenu-container"> //div1
<ul class="mobile-header-nav-submenu"> //div2
<div class="mobile-header-nav-submenu-li-container"> //div3
<?php foreach($submenu as $sub) :?>
<?php if ($men["titre"] == $sub["parentmenu"]) : ?>
<li id="<?php echo $sub["titre"]?>" class="mobile-header-nav-submenu-li">
<a class="" href="<?php if($sub["lien"]){echo $baseUrl.$sub["lien"];}else{echo '#';}?>">
<?php echo $sub["titre"]?>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</div>
</ul>
</div>
</li>
<?php endforeach; ?>
</div>

CodeIgniter: Dropdown Within a Dropdown

Image of the navigation bar
The "User" should be a dropdown. The sub-menu are the ones below it
This is the code I have. How do you make the second condition a DROPWDOWN WITHIN A DROPDOWN? (the elseif part)
<ul class="nav navbar-nav">
<?php
foreach ($nav as $item) {
if (empty($item['children'])) {
?>
<li<?php if (!empty($item['is_active'])) { ?> class="active"<?php } ?>>
<a href="<?php echo $item['link']; ?>"><?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>" data-toggle="tooltip" data-placement="bottom" data-original-title="A large tooltip."></i> <?php } echo $item['label']; ?></a></li>
<?php
}
elseif (!empty($item['children']) && empty($item['children/'])) {
?>
<li class="dropdown <?php if (empty($item['children'])) { ?> active<?php } ?>">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
<?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>"></i>
<?php echo $item['label']; ?>
<b class="caret"></b><?php } ?>
</a>
<ul class="dropdown-menu scrollable-menu" role="menu">
<?php
_main_menu_widget_display_children($item['children']);
?>
</ul>
</li>
<?php
}
else
{
?>
<li class="dropdown <?php if (!empty($item['is_active'])) { ?> active<?php } ?>">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
<?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>"></i>
<?php echo $item['label']; ?>
<b class="caret"></b><?php } ?>
</a>
<ul class="dropdown-menu scrollable-menu" role="menu">
<?php
_main_menu_widget_display_children($item['children']);
?>
</ul>
</li>
<?php
}
}
?>
</ul>

If there is no post in a category, how to hide it

If there is no post in category 19, how can I hide Products in html?
<div id='cssmenu'>
<ul>
<li class='active'><a href='#'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>Products</span></a>
<ul >
<?php query_posts('showposts=5&orderby=date&cat=19'); ?>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" ><li><?php the_meta(meta_key); ?><?php the_title(); ?> </li></a>
<?php endwhile; ?>
</ul>
</li>
</ul>
</div>
example menu is here : http://cssmenumaker.com/menu/modern-jquery-accordion-menu
You can do something like this from server side
<div id='cssmenu'>
<ul>
<li class='active'><a href='#'><span>Home</span></a>
</li>
<?php query_posts( 'showposts=5&orderby=date&cat=19'); if(have_posts()):?>
<li class='has-sub'><a href='#'><span>Products</span></a>
<ul>
<?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<li>
<?php the_meta(meta_key); ?>
<?php the_title(); ?>
</li>
</a>
<?php endwhile; ?>
</ul>
</li>
<?php endif;?>
</ul>
</div>
Using jQuery check and filter the empty product item by count of li elements and hide them
$('.has-sub').filter(function(){
return $('ul li',this).length == 0;
}).hide()
try this,
<?php query_posts('showposts=5&orderby=date&cat=19'); ?>
<?php if(have_posts()) { // <------ check before entering while.
while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>" ><li><?php the_meta(meta_key); ?><?php the_title(); ?> </li></a>
<?php } endwhile; ?>

Categories