Handling of “Back to Home” population with PHP in

2019-07-22 15:20发布

I'm attempting to have a Title and URL populate based off the parent child relationship. I've been able to work with other developers here on Stackoverflow (ref: Echo the subtitle of a PARENT page within WordPress - Part (2)) to mimic a similar function based off of data gathered from tables, however, this will be static information that is populated.

What I need to be done:

If you are on the Homepage or using the "Default" template for the page, the Title will be "Homepage" and the URL will be "http://example.com". In this scenario the page id will be "0" for the homepage and any children will share this relationship based off of "0".

If you are on a Sub-brand homepage or a page using this template, the Title will be "Sub-brand" and the URL will be "http://example.com/sub". In this scenario the homepage id will be "67" and any children will share this relationship based off of "67".

Current version of the function:

<?php 
    if ($post->post_parent!=67) {
        // Sub-brand - children
        echo = "Sub brand child";
        $title .= "Sub-brand";
        $link .= "\nhttp://example.com/sub";
    } elseif($post->ID==0||count(get_pages('child_of='.$post->ID))!=67) {
        // Sub-brand - home
        echo = "Sub brand home";
        $title .= "Sub-brand";
        $link .= "\nhttp://example.com/sub";
    } else {
        // Homepage and children
        echo = "Everything else";
        $title .= "Homepage";
        $link .= "\nhttp://example.com/";
    }
?>

Current issue(s):

  • The homepage is being categorized under the initial "if" statement instead of "else"
  • The child pages that are using the "Homepage" as the parent are being associated with the "elseif" statement instead of "else"

What's working:

  • The Sub-brand homepage is properly being populated by the initial "if" statement
  • The child pages that use "Sub-brand" as the parent are being associated with the "elseif" statement

Any help would be appreciated with getting the associations correct. Be aware, I've been working with PHP for less than a week and I'm learning as I go.

0条回答
登录 后发表回答