Grow your CSS skills. Land your dream job.

Load PHP file if parent and child of parent

  • # May 3, 2013 at 5:50 pm

    I am building a website in WordPress and have a set of photos that display along the top of the page (in the background) and have them to where the set of photos can change depending on where the visitor is on the website. For example, if they are looking at the FAQ page, then photos pertaining to asking questions are shown. If they are looking at the news page, then photos pertaining to news are shown. The code I have works great, however, I’d like to now show photos based on a specific parent and any children of the parent.

    Here’s my code as it stands now:

    `< ?php if ( is_front_page() ) { include'media/home.php'; } elseif ( is_404() ) { include'media/404s.php'; } elseif ( is_page('news') ) { include'media/home.php'; } elseif ( is_page('faqs') ) { include'media/faqs.php'; } elseif ( is_category('africa-2') ) { include'media/faqs.php'; } else { include'media/general.php'; } ?>`

    How can I tell WordPress, I want it to show a certain php file if it is a parent page and all of it’s children?

    # May 11, 2013 at 2:57 am

    Not a wordpress user , but I do way too much PHP [probably need a 12 step program by now] :)
    depending on exactly what you want and how wordpress is actually laid out , one might find the
    get_included_files function useful as it maintains a list of all the files involved in the production of any page. Then one could have some simple XML ,JSON, or even plain old text file where you could store your rules that could be read in to decide when and where to include content.

    Another possibility that might be easier is some sort of .htaccess mod-rewrite rule that you could set in any directory you liked that could add something to the url so you would only have to check for one thing in the PHP but otherwise not have to fiddle with the PHP scripts after the one time.

    Generally I try in my PHP projects to generify and externalize things so I don’t have to be editing PHP files. To many other aspects of development that are much more fun.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".