cinos11 Posted February 27, 2010 Share Posted February 27, 2010 How would you make pages like wordpress does in the sense of website.com/?page=main I want to be able to have all my urls use this format so i can just change the word of main to a page i made for lets call download making it website.com/?page=download. How would i be able to do this like other websites have done? Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/ Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 to do this, you have the actual page content stored in a database, and it is retrieved by page name to display. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019134 Share on other sites More sharing options...
SchweppesAle Posted February 27, 2010 Share Posted February 27, 2010 use the $_GET superglobal <?php if(isset($_GET['page']) { $currentPage = $_GET['page']; } //do something with currentPage, maybe query the database as the previous post suggested ?> Keep in mind, Wordpress is an actual CMS. The code necessary to build your own is not even nearly this simple. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019136 Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 What SchweppesAle has posted is how you get the page from the url. You then need to use that to get the relevant page that you will have stored in the db Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019139 Share on other sites More sharing options...
cinos11 Posted February 27, 2010 Author Share Posted February 27, 2010 I do not want to have anything to do with a database using Mysql. I just want it where it will look like website.com/?page=main while keeping all webpages stored under a different php file to know where the pages main should load and for other pages. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019144 Share on other sites More sharing options...
jl5501 Posted February 28, 2010 Share Posted February 28, 2010 You asked how wordpress does that. The answer is, it uses a database. With the database solution it can be done. With wanting to make it redirect to other files, then that can also be done, but in my opinion that would be harder, and difficult to maintain. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019147 Share on other sites More sharing options...
cinos11 Posted February 28, 2010 Author Share Posted February 28, 2010 Well ive seen a code where it goes something like header (?page) case = main include file.php include /file.php case = download include pages/download.php include page/footer.php Well it was something like that. But i dont know how to get it to work like that and have the url look like the way i want it to be EDIT: I found part of the code that one of the website has: switch($getcype){ case NULL: header('Location: ?cype=main'); break; case "main": include($styledir."/header.php"); include("sources/public/main.php"); include($styledir."/footer.php"); break; case "ucp": include($styledir."/header.php"); include("sources/ucp/main.php"); include($styledir."/footer.php"); break; case "admin": include($styledir."/header.php"); include("sources/admin/main.php"); include($styledir."/footer.php"); break; case "gmcp": include($styledir."/header.php"); include("sources/gmcp/main.php"); include($styledir."/footer.php"); break; case "bbs": include($styledir."/header.php"); include("sources/bbs/main.php"); include($styledir."/footer.php"); break; case "misc": include("sources/misc/main.php"); break; case "style": include($styledir."/header.php"); include("sources/public/styles.php"); include($styledir."/footer.php"); break; case "cypedl": include("sources/misc/phpdownload.php"); break; default: include($styledir."/header.php"); include("sources/public/main.php"); include($styledir."/footer.php"); break; I just don't know how to get it to work knows this kind of information Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019150 Share on other sites More sharing options...
Kingy Posted February 28, 2010 Share Posted February 28, 2010 <?php $page = (isset($_GET['page'])) ? $_GET['page'] : ''; switch($page) { case 'news': include('news.php'); default: include('main.php'); } ?> Just add more cases to it, then point your browser to the page index.php?page=news etc. When you don't specify a page= or it the one you do specify doesn't exist then it'll auto revert to main.php Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019154 Share on other sites More sharing options...
cinos11 Posted February 28, 2010 Author Share Posted February 28, 2010 Which part of the code do i change so the website.com/page.php?(>>>)page(<<<)=hireus will be different. Or how about could i be able to have different webpages using the same file with like website.com/page.php?wow=hireus website.com/page.php?page=newpeople website.com/page.php?zomg=wasup Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019155 Share on other sites More sharing options...
Kingy Posted February 28, 2010 Share Posted February 28, 2010 well using ?one= ?two= or whatever you'll need to use the $_GET method to retrieve all the info page.php?wow=hireus $str = $_GET['wow']; str will equal hireus. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019156 Share on other sites More sharing options...
cinos11 Posted February 28, 2010 Author Share Posted February 28, 2010 Well i tried using this code i tried making using the code provided above. But when i use the website.com/page.php?ha=hireus i get the page to load correctly but this error shows up above the whole website how do i fix it?: Warning: include(main.php) [function.include]: failed to open stream: No such file or directory in C:\Server\www\myserver.dev\vhost\REMOVED\public\page.php on line 11 Warning: include() [function.include]: Failed opening 'main.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\Server\www\myserver.dev\vhost\REMOVED\public\page.php on line 11 This is the code i made using the code provided: <?php $page = (isset($_GET['page'])) ? $_GET['page'] : ''; $ha = (isset($_GET['ha'])) ? $_GET['ha'] : ''; switch($page) { case 'hireus': include('page/hireus.php'); default: include('main.php'); } switch($ha) { case 'hireus': include('page/index.php'); default: include('main.php'); } ?> EDIT: For the ha one, the page loads but it loads using the default part of the code of page/index.php it doesnt get the page i picked for it to load, how do i fix it? Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019157 Share on other sites More sharing options...
Kingy Posted February 28, 2010 Share Posted February 28, 2010 you'll need a seperate switch statement for $ha... Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019173 Share on other sites More sharing options...
cinos11 Posted February 28, 2010 Author Share Posted February 28, 2010 Thank you this thread i have made has been resolved. Link to comment https://forums.phpfreaks.com/topic/193599-making-pages-using-one/#findComment-1019176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.