Handling of “Back to Home” population with PHP in WordPress

放肆的年华 提交于 2020-01-05 05:38:13

问题


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.

来源:https://stackoverflow.com/questions/18318168/handling-of-back-to-home-population-with-php-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!