- b2evolution CMS User Manual
- Developer Reference
- How to... (Customize)
- How to call a blog through xyz.php instead of index.php?blog=x
How to call a blog through xyz.php instead of index.php?blog=x
This man page refers to b2evolution 0.9.2
Let's assume you have a default installation of b2evolution:
- Blog All can be accessed through
index.php?blog=1
- Blog A can be accessed through
index.php?blog=2
- Blog B can be accessed through
index.php?blog=3
- The Linkblog can be accessed through
index.php?blog=4
Let's start with Blog A
Let's start with blog A, because it is the easiest. b2evolution ships with an alternative file to call blog A! In your URL, try replacing the end index.php?blog=2
with a_stub.php
. You should access the exact same page. That's because b2evolution ships with the file a_stub.php
which is preconfigured for acting as if index.php
was called with parameter blog=2
.
However, if you now click on an internal link on this page, say "Last comments", you will notice that b2evo throws you back to index.php?blog=2
!
That's because b2evo doesn't know (yet) that you want to use a_stub.php
instead of index.php?blog=2
. You must set this up in the admin, under blogs then Blog A. Under "Preferred access type:", you must select "Explicit reference to stub file (Advanced)" and then name the stub file name in "Stub name:"; here you should enter a_stub.php
. Validate your changes.
Now, you can refresh the blog page and click on some links. You will notice that you now stay on a_stub.php
and no longer get redirected to index.php?blog=2
.
Now with Blog B
Try the same operations as above on blog B (blog number 3) and try to associate it with a stub file named b_stub.php
. You will notice that you get a "404 Page not found" error from your webserver!
That is because b2evolution does not ship with a file named b_stub.php
!
Now try to duplicate the file a_stub.php
as b_stub.php
on your webserver.
What happens if you acces this page? You will notice that you no longer get an error, but b_stub.php
displays Blog A just as a_stub.php
did! This is not what you wanted!
This happends because b_stub.php
contains preset parameters so that you don't have to pass these on the URL. In this case, it contains a hardcoding for blog=2
and blog #2 is blog A, not blog B. (You can see the blog numbers in the admin, under Blogs).
To correct that, you must open the file b_stub.php
with a text editor and find the following line:
$blog = 2; // 2 is for "demo blog A" or your upgraded blog (depends on your install)
Replace this line with:
$blog = 3;
Take special care not to forget the $ sign in front of $blog
, as well as the semi column ( ; ) at the end of the line. The white space and the comment after // can be omitted.
Save the file (and upload it to your webserver if necessary).
Calling b_stub.php
should now work as expected. :)
The file b_stub.php
is what we call a Stub File. You may have noticed that it also lets you set other parameters than just the blog number. For more information on this, see Stub File.