vendredi 8 mai 2015

How to check if the parent category has specific children

I want to check if the parent category has specific children eg check Category "colors" if it has children "red", "green", "blue", "yellow" and for example the current page might only show colors "red" and "yellow"

I made a custom function which is displayed at the top but at the moment it displays "red" "green" "blue" "yellow" all the time

I was thinking of using

$term = term_exists('Uncategorized', 'category');
if ($term !== 0 && $term !== null) {
 echo "'Uncategorized' category exists!";}

but that only checks if the category exists,

the actual full code

if (strpos ($path, 'build-your-own')) 
            {    
                if ($build > 0) 
                {
                    $array = explode('/',$path);

                    $slice = (array_slice($array, 3, 1));  

                    foreach($slice as $key => $location);
                    {
                        $result = count ($array);
                        if ($result <= 6) 
                            {
                                $link = "./";
                            }
                        else
                            {
                                $link = "../";
                            } 
                    }       
                }
                     $display = true;
            }       
            elseif (strpos ($path, 'ideas'))
            {
                if ($build > 0) 
                {

                    $array = explode('/',$path);

                    $slice = (array_slice($array, 2, 1));  

                    foreach($slice as $key => $result);

                    $re = "~-[^/-]+(?![^-]*-)~"; 
                    $str = "$result";
                    $subst = ""; 
                    $location = preg_replace($re, $subst, $str, 1);
                    {
                        $result = count ($array);
                            if ($result <= 6) 
                                {
                                    $link = "./../../../";
                                }
                            else 
                                {
                                    $link = "../../../../";
                                }
                    }
                        $display = true;
                }
            }
                    if ($display == true)
                    {                       
       ?>
  <div class= "colors">
    <ul>
     <li>Red</li>
     <li>Green</li>
     <li>Blue</li>
     <li>Yellow</li>
    </ul>

Ignore the $link, I use them in the actual code but it was too long to copy into here

Aucun commentaire:

Enregistrer un commentaire