Hello,
A few days ago IDK.in blog wrote an article about creating 404 error pages in phpLD. Those codes were specifically for phpLD 3.x versions.
Sitting down i wrote a small snippet which would allow phpLD users to create a 404 page with phpLD 2.1.2 also!!!
here goes:
open index.php and find the following code:
$id = get_category();
if (!$tpl->is_cached('main.tpl', $id))
{
$path = get_path($id);
Replace the whole block by:
$id = get_category();
if($id==0 && strlen(request_uri()) > 2 && request_uri() != '/index.php' && !isset($_REQUEST['q']))
{
$path[] = array ('ID' => '0', 'TITLE' => _L('404 Page Not Found'), 'TITLE_URL' => '', 'DESCRIPTION' => '');
$tpl->load_filter('output', 'trimwhitespace');
echo $tpl->fetch('page404.tpl');
@ exit(0);
} else if (!$tpl->is_cached('main.tpl', $id)) {
$path = get_path($id);
2. create a new file called page404.tpl, and save it in the templates directory, with the following code
page404.tpl:
{capture name="title"}{l}404 Page not Found{/l} - {/capture}
{capture assign="in_page_title"}{l}404 Page not Found{/l}{/capture}
{capture assign="description"}{l}404 Page not Found{/l}{/capture}
{include file="header.tpl"}
{include file="top_bar.tpl"}
{strip}
<h3 class="box_header">{l}{$in_page_title}{/l}</h3>
<p class="paddcontent">
<table class="formPage" style="clear: both; margin-top: 3em" align="center" border="0" width="80%">
<tr>
<td class="err">
<h2>{l}Error: 404 Page not Found{/l}</h2>
{l}The page you were looking for cannot be found.{/l}</td>
</tr>
</table>
{include file="footer.tpl"}
{/strip}
upload this to /templates/ directory,
and upload your index.php file and your done!
hope this helps someone
Regards,
M.
Changelog:
24-Aug-07:
1. I got PMs from people having issues on the windows server, so now we use phpLD function “request_uri()”, instead of $_SERVER variable.
2. If someone searches something less than 2 characters in length, it was returning a 404 page, the problem has been fixed above.

How can i create custom 404 error page for phpLD v3.1 ?????
Hi Selvam,
you could look into this. http://www.idk.in/blogs/?p=57
M.
Hi,
I think it’s necesary to add this line: header(“http/1.0 404 Not Found”); in order to the server returns a 404 status… if not it returns 200 (ok)
if($id==0 && strlen(request_uri()) > 2 && request_uri() != '/index.php' && !isset($_REQUEST['q']))
{
header("http/1.0 404 Not Found");
$path[] = array ('ID' => '0', 'TITLE' => _L('404 Page Not Found'), 'TITLE_URL' => ”, 'DESCRIPTION' => ”);
$tpl->load_filter('output', 'trimwhitespace');
echo $tpl->fetch('page404.tpl');
@ exit(0);
} else if (!$tpl->is_cached('main.tpl', $id)) {
$path = get_path($id);
Hi,
you could put a http 404 header OR the tpl, either works just fine,
putting a 404 will dispay a normal 404 pag, using the hack as is will display a custom 404 page.
Regards,
M.
The addition of the line :
header(“http/1.0 404 Not Found”);
as indicated by Travel 2.0 is necessary if you want to use google webmaster tools. Without it you will display a 404 page but it will return “200 OK” instead of the “404 Not Found” it is looking for.
The hack with the header line worked for me.
first of all thank you and travel2.0 for the solutions.
I also found many errors in google webmaster tools
However, after applying this mod I still some problems.
i think the best way to describe is to give an example
/automotive/subcategory/arts/crafting/
automotive and arts are two main categories. in case of this url it will not be redirected to the 404 page, instead you see all the subcategories and links of the crafting category eventhough this structure does not exist.
I have the same problem.
You can see here:
http://www.webdirector.dap.ro/comunitati/something/service_pc/
It appears that the idk directory and blog is no longer and the article isn’t available anymore. Would you happen to have the original code for phpLD 3x versions of this snippet? That would be great!
@Simeone – this is a bug of phpLd 2.x , u should get in touch with support for this.
@Madmouse Web Directory – no i dont have the priginal codes, perhaps you could get in touch with “Smub” http://forums.digitalpoint.com/member.php?u=27173 he could possibly have the codes.