• Resolved hollywooood

    (@hollywooood)


    Hey all,

    I am working with a customized template for a photographer site. There is a plugin where the admin can add galleries. Each gallery is created using a Category name and Sub Category which is stored in a table of it’s own in the DB.

    I need to display the current page/category name on the site.

    Since the names of each possible “page” name is not only stored in wp_title(); I need to grab the other possibilities from my new table.

    if these two are non existent then I need to display “HOME” for the page title.

    Here is where my if statement comes in.

    $pages = wp_title("",true);
    
    if($subCats) { $allcat =  "$cats : $subCats";
    
    }
    elseif(!$subCats) { $allcat =  "$pages";
    }
    
    else {  $allcat =  'HOME';
    
    }

    Now, it’s grabbing everything perfectly BUT the last else statement.

    I have also tried to reorder them and still that last else statement doesn’t do it.

    I really hope I have been clear here as to my troubles and hope someone can help me out.

    Thanks in advance for taking a look,

Viewing 4 replies - 1 through 4 (of 4 total)
  • https://codex.www.ads-software.com/Function_Reference/wp_title

    $echo
    (boolean) (optional) Echo the title (True) or return the title for use as a PHP string (False).
    Default: True
    1 (True) – default
    0 (False)

    $pages = wp_title("",false);
    Thread Starter hollywooood

    (@hollywooood)

    Either way that last else is just not coming through. It’s so odd. The $pages = wp_title("",false); works great as well as $pages = wp_title("",true); . I can’t see a logical explanation as to why this wouldn’t work. I really need that to say ‘HOME’ if no $pages or $subCats.

    Pulling my hair out here…

    Thank you very much for the reply alchymth…

    the ‘else’ will never get picked because in any case one of the conditions before will be ‘true’;

    there is no conditional test for ‘pages’ in your logic; possibly try to include some code with:

    elseif( is_page() ) { ... }

    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter hollywooood

    (@hollywooood)

    Beautiful….Your first statement ignited the fire.

    Changed it to this

    $pages = wp_title("",false);
    
    if($subCats) { $allcat =  "$cats : $subCats";
    
    }
    elseif($pages) { $allcat =  "$pages";
    }
    
    else  {  $allcat =  'HOME';
    
    }

    and it works beautifully. Big appreciation your way.

    Thanks a million…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Elseif statement fails for some odd reason…’ is closed to new replies.