Welcome to Deadbeef.com
Articles and tips on software from authored by Jeremy Bettis.

Search

XML Feed RSS

What is RSS?

Who's Online?

  • Guest Users: 6

B2Evolution: Remove dates from permalinks hack

12/21/05

Permalink 03:53:24 pm, by Jeremy Email , 323 words, 5977 views   English (US)
Categories: B2Evolution

B2Evolution: Remove dates from permalinks hack

Here is a little hack to remove the dates from the permalinks, so that they will appear as http://www.example.com/index.php/posttitle instead of http://www.example.com/index.php/2005/12/12/posttitle.

These instructions are for B2Evolution 1.6, since there is an existing hack for older versions.

[More:]

First edit the file evocore/_blog_main.inc.php
At around line 241 you will find this code:

                                { // We consider this a week number
                                        $w = substr( $path_elements[$i], 1, 2 );
                                }
                        }
                        else
                        {       // We did not get a number/year...
                                $path_error = 404;
                        }

Change it to:

                                { // We consider this a week number
                                        $w = substr( $path_elements[$i], 1, 2 );
                                }
                        }
                        else if( isset( $path_elements[$i] ) && (!empty( $path_elements[$i] )) )
                        { // We'll consider this to be a ref to a post
                                // We are accessing a post by permalink
                                // Set a lot of defaults as if we had received a complex URL:
                                $m = '';
                                $more = 1; // Display the extended entries' text
                                $c = 1;    // Display comments
                                $tb = 1;   // Display trackbacks
                                $pb = 1;   // Display pingbacks

                                if( preg_match( "#^p([0-9]+)$#", $path_elements[$i], $req_post ) )
                                { // The last param is of the form p000
                                        // echo 'post number';
                                        $p = $req_post[1];              // Post to display
                                }
                                else
                                { // Last param is a string, we'll consider this to be a post urltitle
                                        $title = $path_elements[$i];
                                        // echo 'post title : ', $title;
                                }
                        }
                        else
                        {       // We did not get a number/year...
                                $path_error = 404;
                        }

If that code looks familar, it is because it was copied from the code at line 217 in that same file. That is code that is normally used after tearing off the Y/M/D.
That takes care of parsing the urls to get to the right post. Now we need to change the permalink generation. Edit the file evocore/_item.class.php in the function gen_permalink, near line 2427.

Find this code:

                                        // This is THE CLEANEST available: RECOMMENDED!
                                        $permalink = url_add_tail( $blogurl, mysql2date("/Y/m/d/", $post_date).$urltail );

Change it to:

                                        // This is THE CLEANEST available: RECOMMENDED!
                                        $permalink = url_add_tail( $blogurl, '/'.$urltail );

Comments, Pingbacks:

Comment from: Tara C. [Visitor] · http://www.dementedkitty.com
Not bad. It's quick and not too difficult to impliment after a new version release. Have is been tested on a b2evo install that hosts multiple blogs across multiple domains?
PermalinkPermalink 12/21/05 @ 20:02
Comment from: Jeremy [Member] Email · http://www.deadbeef.com
I have two blogs here in separate folders. One at http://www.deadbeef.com and http://www.deadbeef.com/jeremy and things work. I have not tested this where the blogs are on different domains.
PermalinkPermalink 12/22/05 @ 08:34
Comment from: personman [Visitor]
Works great for me. I'm using 1.8-cvs. Thanks!
PermalinkPermalink 04/21/06 @ 16:54
Comment from: Danny Ferguson [Visitor] Email · http://www.brendoman.com/dbc
I have this working with 1.8, beta. The only thing that changed is the file locations:
/inc/_blog_main.inc.php
/inc/MODEL/items/_item.class.php

PermalinkPermalink 07/20/06 @ 13:35
Comment from: Finkregh [Visitor] Email · http://mafia-server.net/blog
is it somehow possibe to add a 503 (site moved) so already existing permalinks in the "old" date-style?
PermalinkPermalink 08/24/06 @ 13:58
Comment from: Jeremy [Member] Email · http://www.deadbeef.com
The old date-style permalinks will still work just fine. I suppose you could go in and put in redirects, but I didn't bother, since I implemented this change before any of my permalinks were released into the wild.
PermalinkPermalink 08/24/06 @ 15:27
Comment from: Anne [Visitor] Email · http://www.hungryfeelings.be
Do you use this in 1.8.2 ?
Because for the naked eye, it does what it is suppose to do, but there are a few downsides.
Very odd, but registering new users is down...
Is this only my installations (5) or do you have that problem to ?
PermalinkPermalink 10/21/06 @ 04:02
Comment from: CMB [Visitor] Email · http://www.geometricrate.com/blog/
This still works as of version 1.9.2, with a couple of minor differences:

The first file to be changed is now:
/inc/_blog_main.inc.php
This should be altered as described in the main post.


The second is file is now:
/inc/MODEL/items/_item.functs.php
The function that needs editing is get_permalink (for some reason the archives plugin currently uses the deprecated get_permalink rather than its replaced version get_permanent_url).

I have never done any php before so I reckon this hack is probably a real mess, but it works :)

Find the bit of code that the main post tells you to change, and alter it to:
//This is THE CLEANEST available: RECOMMENDED!
$permalink = $file.mysql2date("", $postdata['Date']).'/'.strtolower($title);
PermalinkPermalink 03/24/07 @ 07:56
Comment from: Mark DeNio [Visitor] Email · http://www.rightlydivide.info/
I'm using 1.9.3 and had to make two modifications:

The main post modification for /inc/_blog_main.inc.php is still correct.

I changed /inc/MODEL/items/_item.funcs.php to:


//This is THE CLEANEST available: RECOMMENDED!
$permalink = $file.mysql2date("", $postdata['Date']).'/'.$anchor;



I also wound up changing the archives plugin file /plugins/_archives.plugin.php (around line 243).

Here's the original code:


{ // We want to link to the absolute canonical URL for this archive:
echo get_permalink( $Blog->get('url'), $post_ID, 'id' );
}



I changed the 'id' parameter to 'title'.


{ // We want to link to the absolute canonical URL for this archive:
echo get_permalink( $Blog->get('url'), $post_ID, 'title' );
}



I don't have my site converted to b2e yet. Just learning on a local install first.
PermalinkPermalink 04/03/07 @ 14:33

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

August 2008
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Sponsored Links

Categories

powered by
b2evolution