bronzemonkey Posted July 21, 2007 Share Posted July 21, 2007 I could really do with some help on 3 problems I'm having - 3 issues that I think PHP could provide answers. They all come down to inserting some xhtml if certain conditions are met, and with housing several variations on the xhtml in a single PHP file which inserts only the correct variant into a page. Any help would be much appreciated. Thanks in advance. How do I use PHP to read the query string of a selected link and write html into the that link? The example is found at this link - http://www.cssplay.co.uk/menus/simple_dropline - where the author states that: As in the previous example, you can now click any of the links, top tabs or dropline, and the page will reload with your selection as the current highlighted choice. This is achieved by reloading the page and using PHP to read the query string of the selected link and write 'current' and 'current_sub' into the styles of that link. Please could someone tell me the PHP that could be used to do this, but to be applied to a proper website so that 'current' can be written into any menu or sidebar navigation link that has been selected by the user. How do I use PHP to display page-specific "related pages" links on a webpage? When a visitor browses any page on my website, I'd like them to be able to see a list of "related pages" with links to other pages on my site that are related to the specific page that the visitor is browsing. Rather than manually adding/removing xhtml to list these specific links on every page (of which there are many!) I was hoping to use just one line of code - <? require("related.php"); ?> - and the related.php file would contain all the page urls of my website and some PHP that would allow me to select which of those urls are to be displayed on different pages within the site. That way, from a single file I can modify the "related pages" links displayed on any page in the website. Effectively allowing me to state "if page-A is being viewed, then display links to pages B, E, Q, Z. if page Z is being viewed, then display links to pages R, S, T" etc. Does anyone know how to do this? Or this there a better way to achieve the same effect? How do I use PHP to write in a specific block of xhtml depending on the page url? I have 5 different "navigation blocks" in my site - one navigation block for each main category of the site. At the moment I have each of these navigation blocks saved as a PHP file. I have to 'include/require' the specific PHP file for a page. So a page that falls within the category of "shoes" (rather than cars or dogs, etc) will require the "shoes-navigation" file. Is there a better way to go about this? Could I just use a single file (e.g. "page-navigations") that contains all 5 navigations and inserts only one of them into a page? So would I be able to use some conditional stuff to say "if the url is a, b, c, d, or e then use navigation1. if the page url is f, g, h, or i then use navigation 2"? Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/ Share on other sites More sharing options...
socratesone Posted July 21, 2007 Share Posted July 21, 2007 How do I use PHP to display page-specific "related pages" links on a webpage? // on the "related.php" included page: // (And this is a quick-and-dirty way of doing it. // The best idea is to use a database of related pages) $currentPage = $_SERVER["PHP_SELF"]; if( strpos($currentPage, 'pageName1') !== false) { $relatedPages = array("link1" => "relatedPage1.htm", "link2" => "relatedPage2.htm"); }elseif(strpos($currentPage, 'pageName2') !== false){ $relatedPages = array("link4" => "relatedPage4.htm", "link3" => "relatedPage3.htm"); }elseif(strpos($currentPage, 'pageName3') !== false){ $relatedPages = array("link1" => "relatedPage1.htm", "link5" => "relatedPage5.htm"); }elseif(strpos($currentPage, 'pageName4') !== false){ $relatedPages = array("link3" => "relatedPage3.htm", "link5" => "relatedPage5.htm"); } Obviously you would want to replace the "pageName1" with the current page, and the "relatedPage1.html" with the related page. Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/#findComment-304139 Share on other sites More sharing options...
bronzemonkey Posted July 21, 2007 Author Share Posted July 21, 2007 Thanks, but I'm not sure how to use the code...do I need to build an array? How could I use that to make sure that the xhtml inserted into the page was of this format: <div id="related"> <h4>Related Pages</h4> <ul> <li><a href="/page1.php">Page1 Title</a></li> <li><a href="/page12.php">Page12 Title</a></li> <li><a href="/page4.php">Page4 Title</a></li> <li><a href="/page7.php">Page7 Title</a></li> </ul> </div> And how could I modify the PHP if I also had a group of "related pages" that I wanted to be displayed by more than a single page? Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/#findComment-304154 Share on other sites More sharing options...
bronzemonkey Posted July 22, 2007 Author Share Posted July 22, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/#findComment-304377 Share on other sites More sharing options...
simon551 Posted July 22, 2007 Share Posted July 22, 2007 you might do something like this: <ul> <?php echo '<li>'.$relatedPages[link1].'</li>'; echo '<li>'.$relatedPages[link2].'</li>'; echo '<li>'.$relatedPages[link3].'</li>'; echo '<li>'.$relatedPages[link4].'</li>'; ?> </ul> in combination with the previous suggestion might do it. Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/#findComment-304385 Share on other sites More sharing options...
bronzemonkey Posted July 23, 2007 Author Share Posted July 23, 2007 Can someone help me out with: How do I use PHP to read the query string of a selected link and write html into the that link? It seems that several people are interested in how to do this but no solutions have been provided yet. Would really help me out. The "related pages" problem is solved. I've played around with both suggestions and it is working. Just one last question about it...I've used the code below so that the markup that is generated fits in with the rest of the document structure, but is it problematic to use multiple echo like this? I was looking to get each <li> displayed on a new line. Thanks for the help. <div id="related"> <h4>Related Pages</h4> <ul> <li><? echo ''.$relatedPages['link1'].'' ?></li> <li><? echo ''.$relatedPages['link2'].'' ?></li> <li><? echo ''.$relatedPages['link3'].'' ?></li> <li><? echo ''.$relatedPages['link4'].'' ?></li> </ul> </div> Quote Link to comment https://forums.phpfreaks.com/topic/61114-help-using-php-to-conditionally-insert-xhtml-based-on-page-urls/#findComment-305389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.