Separate pages for blog posts - php

I'm currently working on my private CMS, mostly just to learn PHP. For now I have very simple way to show post, using GET with ID, for example www.mypage.com/post.php?id=1 and then loading results from DB. But I see that almost all blogs are using other way, which looks like this www.mypage.com/post/lorem-ipsum. I know about removing file extensions but the rest is mystery. Does wordpress and other blog CMS are somehow creating separate files? PHP is huge, and it's hard to find an answer if you don't know it well, so If someone can point me in the right direction, I'll be obliged.

It is possible to rewrite the URL using an .htaccess file: see here

Related

php dynamically create new pages in custom cms

I'm creating my own CMS from scratch as a way to build my php and mysql skills. Everything is going well, but I'm at the point where I want to create individual post pages for each blog post I write. So the index.php page has a list of all my blogs with snippets of each post and there is a read more button that should take the user to the full page for each blog post. Each post has a url created from the blog title entered in the "create post" form. I'm trying to figure out how to create unique pages for each post without passing the title, subhead, post content and other info through the GET.
This also dovetails with another feature I'm trying to add. I want to be able to create individual pages using a "create page" form like I did for my posts. So if I want an "about us" page I go to my admin form, fill out the title, add the content, and when I hit submit it creates the page dynamically. I have thought all day about how I'd do these two things but can't quite figure out how I can do this.
FYI, I'm not asking for code, I just need a push in the right direction as I try to conceptualize how to achieve this. Thanks!
If you're not familiar with the Model-View-Controller pattern, reading up on it might be prudent. MVC is frequently the right starting place for high-level design of web applications.
Also, a CMS is a big enough project you should consider using a PHP framework like CodeIgniter, Symfony, Zend, etc. to make your life easier. It removes a lot of the drudge work and common tasks.
Dynamic Page Creation and Display
I think you want to split it into two things: the text content (basically what you put in the forms) and the HTML templating surrounding that content.
When you make a page or blog post, you would want to store the actual content (what you type into the creation form) in a database of some sort (not necessarily an RDBMS, but if you're trying to build MySQL skills it's a reasonable choice).
Then you would use a separate function to bind that content into an HTML template and present it to the user when they load a given page.
URL Routing
To get nicer-looking URLs you can use something like apache's mod_rewrite. You can use that to convert a URL like this:
posts/how-to-make-a-cms
to this:
posts.php?title=how-to-make-a-cms
Then you can have posts.php read from GET as normal. How you choose to do the conversion is pretty open-ended.
To avoid getting really complicated rewrites, people often just structure everything to go to a central routing script which figures out what class and method to call and what arguments to pass it. So it would rewrite the URL above to:
main.php?a=posts/how-to-make-a-cms
Then main.php would parse out the segments of that argument from GET and figure out where to send them. Like it might take posts/show/how-to-make-a-cms and do something like:
$o = new Posts();
$o->show("how-to-make-a-cms");
If you do it that way, I think you can avoid mod_rewrite entirely as long as you're willing to accept only slightly pretty URLs, like this:
mysite.com/main.php?/posts/show/how-to-make-a-cms
I haven't done this type of thing before (because the frameworks do it so beautifully already), so I might be missing some minor details.
You should watch some tutorials from phpacademy.org or thenewboston.org, they have best and most valuable tutorials ever made about PHP.
I think you may try to start from that course/playlist:
phpacademy.org: PHP Tutorials: Creating a Blog
If you don't understand everything, watch this:
thenewboston.org: Official Beginner PHP Tutorials Playlist!
If you have no problems with PHP itself you may try to use some simple framework with MVC support. That helps A LOT in variable handling between pages, makes work with database easier etc.
phpacademy.org: Introduction to CodeIgniter
phpacademy.org: Introduction to CodeIgniter - Basic Website
I had the same problem. You can easily do this by using the fopen function. Here is a link to a tutorial: http://www.tizag.com/phpT/filecreate.php
<?php
function wwwcopy($link,$file)
{
$fp = #fopen($link,"r");
while(!feof($fp))
{
$cont.= fread($fp,1024);
}
fclose($fp);
$fp2 = #fopen($file,"w");
fwrite($fp2,$cont);
fclose($fp2);
}
//Example on using this function
wwwcopy("http://www.domain.com/list.php?member=sample", "sample.html");
//Another example
wwwcopy("http://www.domain.com/list.php?member=sample2", "sample2.html");
?>

Friendly subfolder link to page (wikipedia style)

I am struggling to find this as I'm not sure exactly what I'm looking for!
I've seen that some sites seem to use 'subfolders' as links to pages, e.g. wikipedia.
E.g. Let's say I had a record in a database with a unique title "My Shopping List". I want to be able to navigate to www.mySite.com/my_shopping_list and have it automatically 'forward' to a page showing the relevant record.
I am using IIS and wondering if there's a way I can do it with that, but I may be looking in the wrong place.
This is for a knowledgebase where I might write an article called "how to use a computer" and would like to be able to create a 'friendly' link for users (http://www.mySite.com/how_to_use_a_computer rather than http://www.mySite.com/article.php?ID=123. I will need to be able to create these 'links' dynamically using the title field.
Thank you
EDIT: I am using IIS6
You should use URL Rewrite, the microsoft ressource for this technique is here: http://www.iis.net/download/urlrewrite
In the iss forum the issue about url rewrite in iss < 7 is discussed with some suggestions on software to use.
I don't know which one is best, maybe there are others who know:
http://iirf.codeplex.com/
http://www.isapirewrite.com/
http://urlrewriter.net/
With PHP, you'll need to code URLConf using something like a htaccess file or the manager GUI. You can read ISS docs on URL rewrite to learn how., but as I understand, this is a module you'll have to download separately.
This question also shows how do do it without editing server configuration files or htaccess, but you'll be stuck with a http://example.com/index.php/path/to/view format (where index.php is a real script with the URLConf in it.)
Well some time ago it was used to call 'Friendly URL' or 'FURL', now i see that it's ust Rewrite URL. Look for tutorials for beginners.

get latest posts from wordpress blog based on tags and display them in base site

this might be easy question for you but not for me as i am really new to wordpress, i have setup Wordpress in my site as blog(and i am quite happy with that),
i want to display some posts from my wordpress blog to my base site, i am looking around but its like headache as i have thousands of references and i am confused,
i want to display posts from certain tags,
any help would be much appreciated. Thanks in advance
Kind Regards
I use a program called rss2html setup with a category parameter. Costs a few bucks, but you can do practically anything with it (or via one of the companion programs available at same site). I have used it tons of times passing a category, custom query, or other parameter to it using the config file.
If you choose to pick up a copy and have questions configuring, gimme a shout, I've done literally hundreds of them.
You can find the program I use here: www.feedforall.com

Creating a Website for a Shop with Multiple Locations

I have a quick question. We are building a site for a shop that has 12 different locations. So there is a Portal page, and then the 12 locations pages.
The design is the same for each location, just different text and rotator images. What I did before for another site was just used PHP and a Database, and had a site.php?shop=city&page=about and just did some rewrites so it would be /city/about/ which works good.
That way when I need to make an overall design change, it will apply to all locations instead of duplicating the site 12 times and if I catch one thing, I need to do it on all 12 sites.
One thing that we don't like about that is if someone in the team needs to make a change to the text, they would need to go in the MySQL Database to make the content changes which they are unfamiliar with. I could create a basic CMS but I would like some suggestions on what else I can do to make this easy on everyone.
If I need to create one of the sites and duplicate it 11 times, I could do that but was just seeing if there were any easier ways you guys know of, where it would still be easy for people to update the content with FTP.
Thanks!
From my point of view you have a few options:
Build a basic update form with a basic WYSIWYG editor, more or less a very basic CMS
Use an include file structure then the user only needs to edit a text file for example for changes to reflect on the site, note they may need to know basic HTML and FTP is likely to be required
Give access to phpMyAdmin, again note they may need to know a little HTML (edit: as already suggested I just noticed, sorry need to load answers while I'm typing)
Install an out of the box CMS in the 'locations' or 'stores' directory and only have it used on these pages
Personally I would just build a simple CMS in this case... then again I have built around 15 CMS' in the past so it only takes me about an hour to code something like this.
Hope that helps you.
It is not ftp, but if you gave them access to phpmyadmin, with a login that only has access to that table then they could edit the data.

Beginning to use wordpress, custom theme?

I'm pretty new to wordpress (only a couple of days), but I have it up and running on my website with the default theme. First of all I would like to change this theme. I have found a tutorial directly from wordpress but it is extremely vague: http://codex.wordpress.org/Theme_Development. I'd like to have a totally different layout for my website though, with only one page being replaced daily with a different article - a new article everyday basically. But I don't know where to start. I want to first create the theme though, I think that will put things in to perspective. How do I do so? I know the principles of php and enough about html and css to create whole websites. Thank you
That link should tell you everything you need to know. You basically just edit the theme files to get the layout that you want. The best way to learn truly is to experiment. If you have a specific question I could help you with that, but to tell everything involved in creating a custom theme would go way beyond the scope of an answer for this site.

Categories