{"id":66,"date":"2004-11-18T19:10:15","date_gmt":"2004-11-18T17:10:15","guid":{"rendered":"http:\/\/www.maratz.com\/blog\/archives\/2004\/11\/18\/faux-active-link\/"},"modified":"2005-10-14T07:06:56","modified_gmt":"2005-10-14T05:06:56","slug":"faux-active-link","status":"publish","type":"post","link":"http:\/\/www.maratz.com\/blog\/archives\/2004\/11\/18\/faux-active-link\/","title":{"rendered":"Faux Active Link"},"content":{"rendered":"<p>Over there at <a href=\"http:\/\/www.themaninblue.com\/\">The Man in Blue<\/a> there\u2019s nice tip about how to <a href=\"http:\/\/www.themaninblue.com\/writing\/perspective\/2004\/11\/19\/\">\u2018hide\u2019 link to a current page<\/a>. Here\u2019s server-side solution to improve your main navigation.<!--more--><\/p>\n<p><em>You should know some basics of PHP or ASP to follow examples below and also rename your files according to server-side technology used. Also, this is way too basic for advanced programmers, so don\u2019t bother if you\u2019re the one. I know i\u2019m not : ).<\/em><\/p>\n<h3>Main Navigation<\/h3>\n<p>Main navigation is usually one unordered list, something like:<\/p>\n<pre>&#60;ul id=\"mainNav\">\r\n    &#60;li>&#60;a href=\"\/\">home&#60;\/a>&#60;\/li>\r\n    &#60;li>&#60;a href=\"\/about\/\">about&#60;\/a>&#60;\/li>    \r\n    &#60;li>&#60;a href=\"\/products\/\">products&#60;\/a>&#60;\/li>\r\n    &#60;li>&#60;a href=\"\/services\/\">services&#60;\/a>&#60;\/li>\r\n    &#60;li>&#60;a href=\"\/contact\/\">contact&#60;\/a>&#60;\/li>\r\n&#60;\/ul>\r\n<\/pre>\n<p>What we are aiming for is to replace <code>&#60;a><\/code> tag with something else, in this case it will be <code>&#60;span><\/code>.<\/p>\n<h3>Particular Pages<\/h3>\n<p>Open each page and place a string on the top of everything else and assign a value which will be descriptive, for example \u201chomePage\u201d, \u201caboutPage\u201d, \u201cproductsPage\u201d, \u201cservicesPage\u201d and \u201ccontactPage\u201d. Something like:<\/p>\n<pre>&#60;?php $pageName = \"homePage\"; ?>\r\n... the rest of HTML\/PHP here...\r\n<\/pre>\n<p>if you are using PHP, or <\/p>\n<pre>&#60;% pageName = \"homePage\" %>\r\n... the rest of HTML\/ASP here...<\/pre>\n<p>if you are using ASP. Repeat this for every page you want&#8230; Next,  cut <code>#mainNav<\/code> unordered list, save it as include file and include it back in the same place of every page you\u2019ve modified\u2013PHP:<\/p>\n<pre>&#60;?php include 'mainNav.php'; ?><\/pre>\n<p>and ASP:<\/p>\n<pre>&#60;!--include file=\"mainNav.asp\" --><\/pre>\n<h3>The Magic<\/h3>\n<p>Here is an example of what <code>mainNav.php<\/code> should look like:<\/p>\n<pre>&#60;ul id=\"mainNav\">\r\n    &#60;li>&#60;?php if ($pageName == 'homePage') { echo '&#60;span>home&#60;\/span>'; } else { echo '&#60;a href=\"\/\">home&#60;\/a>'; } ?>&#60;\/li>\r\n    &#60;li>&#60;?php if ($pageName == 'aboutPage') { echo '&#60;span>about&#60;\/span>'; } else { echo '&#60;a href=\"\/about\/\">about&#60;\/a>'; } ?>&#60;\/li>    \r\n    &#60;li>&#60;?php if ($pageName == 'productsPage') { echo '&#60;span>products&#60;\/span>'; } else { echo '&#60;a href=\"\/products\/\">products&#60;\/a>'; } ?>&#60;\/li>\r\n    &#60;li>&#60;?php if ($pageName == 'servicesPage') { echo '&#60;span>services&#60;\/span>'; } else { echo '&#60;a href=\"\/services\/\">services&#60;\/a>'; } ?>&#60;\/li>\r\n    &#60;li>&#60;?php if ($pageName == 'contactPage') { echo '&#60;span>contact&#60;\/span>'; } else { echo '&#60;a href=\"\/contact\/\">contact&#60;\/a>'; } ?>&#60;\/li>\r\n&#60;\/ul><\/pre>\n<p>and here\u2019s <code>mainNav.asp<\/code>:<\/p>\n<pre>&#60;ul id=\"mainNav\">\r\n    &#60;li>&#60;% If pageName = \"homePage\" Then Response.Write \"&#60;span>home&#60;\/span>\" Else Response.Write\"&#60;a href='\/'>home&#60;\/a>\" End If %>&#60;\/li>\r\n    &#60;li>&#60;% If pageName = \"aboutPage\" Then Response.Write \"&#60;span>about&#60;\/span>\" Else Response.Write\"&#60;a href='about\/'>about&#60;\/a>\" End If %>&#60;\/li>    \r\n    &#60;li>&#60;% If pageName = \"productsPage\" Then Response.Write \"&#60;span>products&#60;\/span>\" Else Response.Write\"&#60;a href='products\/'>products&#60;\/a>\" End If %>&#60;\/li>\r\n    &#60;li>&#60;% If pageName = \"servicesPage\" Then Response.Write \"&#60;span>services&#60;\/span>\" Else Response.Write\"&#60;a href='services\/'>services&#60;\/a>\" End If %>&#60;\/li>\r\n    &#60;li>&#60;% If pageName = \"contactPage\" Then Response.Write \"&#60;span>contact&#60;\/span>\" Else Response.Write\"&#60;a href='contact\/'>contact&#60;\/a>\" End If  %>&#60;\/li>\r\n&#60;\/ul><\/pre>\n<p>Add\/modify as desired, the styling is up to you&#8230;<\/p>\n<h3>Update: JavaScript Solution<\/h3>\n<p>If you don\u2019t have an option to use server-side scripting, there is nice post with explanation and example: <a href=\"http:\/\/www.snook.ca\/archives\/000291.html\">Clear Links to Current Page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over there at <a href=\"http:\/\/www.themaninblue.com\/\">The Man in Blue<\/a> there&#8217;s nice tip about how to <a href=\"http:\/\/www.themaninblue.com\/writing\/perspective\/2004\/11\/19\/\">&#8216;hide&#8217; link to a current page<\/a>. Here&#8217;s server-side solution to improve your main navigation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/posts\/66"}],"collection":[{"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.maratz.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}