adeking Posted August 4, 2008 Share Posted August 4, 2008 Hi, I am looking to build up a website using multiple pages for each component that makes a page - i.e Header, sidebar etc etc. I have decided to build up each page using php include statements. I have immediately became stuck with relative links. The sidebar.php file which includes navigational elements is saved within an includes folder. Once I have added this page to the home page for example (which is saved in the root), none of the links work as they are relative and the page is saved in a different path. I know that a lot of web design agencies use php includes to build up templates in this way so I am sure there must be a solution. Many thanks for your time and I hope I have explained myself..... Link to comment https://forums.phpfreaks.com/topic/118087-php-includes-for-templates-relative-link-problems/ Share on other sites More sharing options...
Johntron Posted August 4, 2008 Share Posted August 4, 2008 Use absolute links, or if you really want relative links, write a function that uses $_SERVER['PHP_SELF'] and the document root to determine the relative paths. Link to comment https://forums.phpfreaks.com/topic/118087-php-includes-for-templates-relative-link-problems/#findComment-607507 Share on other sites More sharing options...
Jabop Posted August 4, 2008 Share Posted August 4, 2008 Links that don't have anything, are relative to the domain. <a href="/page.html">Link</a> Links to www.yoursite.com/page.html You may want to try to explicitly specify the links you're trying to point to. <a href="/dir/folder/page.html">Link</a> Or use aliases in .htaccess or your apache conf. Link to comment https://forums.phpfreaks.com/topic/118087-php-includes-for-templates-relative-link-problems/#findComment-607508 Share on other sites More sharing options...
Johntron Posted August 4, 2008 Share Posted August 4, 2008 That's the absolute links I was talking about. What would you call those then? Relative2? Link to comment https://forums.phpfreaks.com/topic/118087-php-includes-for-templates-relative-link-problems/#findComment-607528 Share on other sites More sharing options...
adeking Posted August 4, 2008 Author Share Posted August 4, 2008 Hi, Thanks for your responses. I knew that absolute links will be one way of getting round the problem - but thought there may be another workaround. Thanks again for your contributions. Link to comment https://forums.phpfreaks.com/topic/118087-php-includes-for-templates-relative-link-problems/#findComment-607759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.