Support » Plugins and Hacks » Hacks » Unique Headers for Tags/Archives/Category Templates

Unique Headers for Tags/Archives/Category Templates

  • Hello,

    Trying to setup the tags/archive/category templates to call unique navigations depending on what page was visited.

    For an example, the page I am on has a blue navigation and I click on the archive for 2013, this takes me to the archive page with the blue navigation. On a page with the red navigation will take me to the archive page with red navigation. I am probably over thinking this in my head but any help will help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator bcworkz


    I think you would want to pass the current color as an URL parameter so the next template can check this parameter and load the correct content associated with that color.

    So when a red page is being loaded, for example, all URL links should have ?color=red appended to them. When one of those links are clicked, the requested template uses $_GET['color'] to get the current color and determine that it should send out ‘red’ content.

    Interesting. I should have explained my example better. Instead of colors, I want to use template php file like the following:

    <?php include (TEMPLATEPATH . '/nav-usa.php'); ?>
    If coming from a page using a page with nav-usa.php.

    <?php include (TEMPLATEPATH . '/nav-uk.php'); ?>
    If coming from a page using a page with nav-uk.php.



    Forum Moderator

    Do not use TEMPLATEPATH. It should only ever be used internally by WordPress core.

    What is an alternative? Also would that alternative work for what I need?



    Forum Moderator

    Try using get_template_part().

    Moderator bcworkz


    As for passing URL parameters, I was pretty sure you were not really trying to pass colors 🙂 The concept still applies though, any meaningful text string can be passed, like the name of the template, or a security hash, or….

    In case you can discern the pertinent information from a permalink, you can get the permalink of the page that sent the user to the current page from $_SERVER[‘HTTP_REFERER’].


    Thank you esmi for the updated template path fix and thank you bcworkz for the server script.

    Back again (sorry!). I was able to get quite the distance with the $_SERVER code, though I ran into a little issue when going from “archive.php” to “single.php” (single post). Apparently going two levels deep, code gets ignored and no navigation shows up.

    Below is what I have thus far.

    	if (strpos("http://web.com/usa/", $_SERVER['HTTP_REFERER']) !== false) {
        	echo get_template_part('nav','template');
    	elseif (strpos("http://web.com/uk/", $_SERVER['HTTP_REFERER']) !== false) {
        	echo get_template_part('nav','uk');
    Moderator bcworkz


    Can’t be too many causes. Either the string match is not found for some reason or the template is not found. Some value is likely not what you expect. Double check the referer field is really what you expect. Consider only providing a needle parameter for strpos() that is essential for identifying the proper template to eliminate stray differences that do not matter, such as an URL like ‘www.web.com/usa/’ which is valid for the match but yet will not match. Perhaps search just for ‘.com/usa’ and ‘.com/uk’?

    To convince yourself that code is or is not being executed, insert error_log() lines at key points with various informative messages that will build a sort of trace path in your error log.

    If it is the template not being found, it may seem silly, but you could even trace through the core code and check key variables in order to identify exactly why a template is not found.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Unique Headers for Tags/Archives/Category Templates’ is closed to new replies.
Skip to toolbar