Recent Topics

Permalinks with a nice multipage URL

Started by on May 22, 2006 – Contents updated: May 22, 2006

May 22, 2006 07:34    

I am developing a corporate-type site using b2evolution (Phoenix). The content doesn't change often, but I like the blogging functionality that b2e has and I'm familiar with it. Since the content doesn't change often I hard-coded my navigation menu to use permalinks to navigate the site, mostly because they look nicer. I used the hack to remove the dates, but I ran into something even uglier.

I have some posts which are multipage entries. On the main navigation menu, you get to a multipage post using the normal attractive permalink, but once you are surfing between pages you get the normal ugly URLs. And what if I wanted to permalink directly to page 3 for some reason? Can't do it currently; not that I found anyway.

So this hack which I am now posting will take the ugly multi-page URL such as this:

/site.com/index.php?p=92&page=3&more=1

And turn it into something like this:

/site.com/index.php/long_article,3

-----

First, in the b2e admin panel, I went to the tab entitled "settings" and turned on "use extra-path info", and for permanlink type I selected the option "post called up by its URL title".

Next, I installed the hack to remove dates from permalinks, as provided by Jeremy Bettis here:
http://www.deadbeef.com/index.php/b2evolution_remove_dates_from_permalinks

My additions below do not require this, so if you want to keep the dates in your URLs that is fine. But why not make them look good all at once? :)

Next, in ./evocore/_blog_main.inc.php find this line:

$title = $path_elements[$i];

and replace it with these lines:

$getpage = explode( ',', $path_elements[$i] );
$title = trim( $getpage[0] );
$page = trim( $getpage[1] );

Finally, in ./evocore/_item.funcs.php find these lines:

if( ($i != $page) || ( (!$more) && ($page==1) ))
echo '<a href="'.url_add_param($file, 'p='.$id.'&amp;more=1&amp;page='.$i).'">';

and replace them with these lines:

global $pagenow;
$newpage = explode( ",", $pagenow );
if( $newpage[1] < 1 ) $newpage[1] = 1;
if( ($i != $newpage[1]) || ( (!$more) && ($page==1) )) {
  $new = "/".$newpage[0].",$i";
  $newurl = '<a href="'.url_add_param($file, $new).'">';
  $done = str_replace( "?".$new, $new, $newurl );
  echo $done;
}

Right under this, find this line:

if( ($i != $page) || ( (!$more) && ($page==1) ))

and replace it with this line:

if( ($i != $newpage[1]) || ( (!$more) && ($page==1) ))

This should replace all b2e generated multi-page links with attractive permalink style multipage links. I'm sure it can be optimized a bit but the above works for me. Now, no one ever has to see ugly URLs on my site, but they can see or even bookmark ones that clearly indicate what they are looking at.

I doubt this works with previous versions of b2e and I won't be modifying it for them. If someone else would like to do so, that would be very cool. I will try and come back and help with any replies, but registering just to post this was annoying so I may not.

Good luck all.

Aug 05, 2007 21:13

Does anyone have any suggestions on how to make this hack:

http://www.deadbeef.com/index.php/b2evolution_remove_dates_from_permalinks

Work for 1.10?

To be clearer, I can get the date out of the links, but that messes up the archives plugin. If I change this:

				{	// We want to link to the absolute canonical URL for this archive:

					echo get_permalink( $Blog->get('url'), $post_ID, 'id' );

to this:

				{	// We want to link to the absolute canonical URL for this archive:

					echo get_permalink( $Blog->get('url'), $post_ID, 'title' );

The archive links have no dates, but the archive links have capital letters that render the links useless.

Aug 06, 2007 11:58

You might get away with :

echo strtolower( get_permalink( $Blog->get('url'), $post_ID, 'title' ) );

¥

Aug 06, 2007 12:58

It's closer! It addresses the case issue. However, it turns this permalink:

http://www.smileysmile.net/index.php/news/the_legend_brian_wilson_opens_at_annenbe

into this:

http://www.smileysmile.net/index.php/news/_the_legend__brian_wilson__opens_at_annenberg_theater

Aug 06, 2007 13:50

lol, ok, lets try it the hard way

global $ItemCache;
$foo = $ItemCache->get_by_ID( $post_ID );
echo $foo->get_permanent_url();

If that works then you might want to move the "global $ItemCache;" to the top of the function to save your cpu a few cycles ;)

¥

Aug 06, 2007 14:10

"Top of the function," as in, the top of the archives plugin file?

Aug 06, 2007 14:28

Assuming I found the right function, it wants to look like this :

	function SkinTag( $params )
	{
	 	global $Settings, $month;
	 	global $ItemCache;

.....

            {   // We want to link to the absolute canonical URL for this archive:
              $foo = $ItemCache->get_by_ID( $post_ID );
              echo $foo->get_permanent_url();

¥

Aug 06, 2007 14:36

I will try that tonight when I get off of work, thanks!

Aug 07, 2007 04:07

That worked perfectly, thank you!

When I get a chance I'll post all the accurate edits, including yours, to make this hack work in 1.10.


Form is loading...

Social CMS software – This forum is powered by b2evolution CMS, a complete engine for your website.