I need your help because I’ve got a feeling I’m running my own tail. Here is the thing – I do have a repeater called ‘sales’. And on my page I wanted to make a sales related subpage where the main subfield is ‘platform’. Because based on that a user should get a dropdown with certain links to other platforms.
This is my current code:
<ul class="menu">
<?php
$pc_parent = array('pc-steam', 'pc-epic', 'pc-gog');
$ps_parent = array('ps4', 'ps5');
$svg_container = '';
$element_visibility = ' d-none';
$pc_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 92 70"><use xlink:href="#svgPCblack" id="svgPCblackContainer"></use></svg>';
$ps_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 110 85"><use xlink:href="#svgIconPS4Black" id="svgIconPS4BlackContainer"></use></svg>';
$xbox_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 94 94"><use xlink:href="#svgIconXboxBlack" id="svgIconXboxBlackContainer"></use></svg>';
$nx_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 97 24"><use xlink:href="#svgLogoNintendoBlack" id="svgLogoNintendoBlackContainer"></use></svg>';
if( have_rows('sales') ):
while( have_rows('sales') ) : the_row();
$platform = get_sub_field('platform');
$pc_parent = array('pc-steam', 'pc-epic', 'pc-gog');
$ps_parent = array('ps4', 'ps5');
if (in_array($platform, $pc_parent)) {
echo '<li class="dropdown">';
echo $pc_svg;
echo '<ul class="dropdown_menu dropdown_menu--animated dropdown_menu-8">';
if($platform == 'pc-steam'){echo '<li class="dropdown_item-1"><a href="" target="_blank">STEAM</a></li>';}
if($platform == 'pc-epic'){echo '<li class="dropdown_item-2"><a href="" target="_blank">EPIC STORE</a></li>';}
if($platform == 'pc-gog'){echo '<li class="dropdown_item-3"><a href="" target="_blank">GOG.COM</a></li>';}
echo '</ul></li>';
}
elseif (in_array($platform, $ps_parent)) {
echo '<li class="dropdown">';
echo $ps_svg;
echo '<ul class="dropdown_menu dropdown_menu--animated dropdown_menu-8">';
if($platform == 'ps4'){echo '<li class="dropdown_item-1"><a href="" target="_blank">PS4</a></li>';}
if($platform == 'ps5'){echo '<li class="dropdown_item-2"><a href="" target="_blank">PS5</a></li>';}
echo '</ul></li>';
}
elseif ($platform == 'xbox') {
echo '<li class="dropdown">';
echo $xbox_svg;
echo '<ul class="dropdown_menu dropdown_menu--animated dropdown_menu-8">';
if($platform == 'xbox'){echo '<li class="dropdown_item-1"><a href="" target="_blank">XBOX</a></li>';}
echo '</ul></li>';
}
elseif ($platform == 'nx') {
echo '<li class="dropdown">';
echo $nx_svg;
echo '<ul class="dropdown_menu dropdown_menu--animated dropdown_menu-8">';
if($platform == 'nx'){echo '<li class="dropdown_item-1"><a href="" target="_blank">NX</a></li>';}
echo '</ul></li>';
}
endwhile;
else : 'No content found :-(';
endif;
?>
</ul>
While the code displays correct values, the way its served is wrong. At the moment If I create a row dedicated to PC Steam sale, then it shows only one link. But if I want to have couple of them – while loop keeps adding parent container ‘’. In the ideal solution what I’m trying to achieve is to have a one, common parent LI under which will have other links.
So showing it on a example – this is I would like to achieve:
<main platform link e.g. PC>
<sales link1 e.g. steam>
<sales link2 e.g. epic store>
<sales link3 e.g. gog.com>
Currently it works that way:
<main platform link e.g. PC>
<sales link1 e.g. steam>
<main platform link e.g. PC>
<sales link2 e.g. epic store>
<main platform link e.g. PC>
<sales link3 e.g. gog.com>