WordPress for Joomla: Author Archive SEF Link setup

WordPress for Joomla

WordPress for Joomla


Recently I setup and tuned CorePHP WordPress for Joomla component for one of my clients site.
One task I had to resolve was to show all posts of the selected author if visitor click on the author name. I used WordPress the_author_posts_link() function to get the URL to the author archive page.
It returned
www.yoursite.com?authour=nnn
URL instead of search engine friendly (SEF) permalink. In order to change that I use the way I was found at
codex.wordpress.org.
In order to setup the author permalink instead of ?authour=nnn I placed this code to the end of functions.php file at WordPress default used theme folder:

function change_author_permalinks() {
 
    global $wp_rewrite;
 
    $wp_rewrite->author_structure = $wp_rewrite->front .'/'. $wp_rewrite->author_base . '/%author%';
    $wp_rewrite->flush_rules();
}
 
add_action('init','change_author_permalinks');

At this stage I have got such URL as
http://www.yoursite.com/component/wordpress/author/authorname
But I needed more search engine friendly URL such as
http://www.yoursite.com/mobile-news/author/authorname
After source code investigation I discovered that
http://www.yoursite.com/component/wordpress/
goes from WordPress ‘home’ option (General Settings) where we have this
http://www.yoursite.com?option=com_wordpress
When I simply changed this URL to the
http://www.yoursite.com/mobile-news
where ‘mobile-news’ is a SEF link to my wordperss component under Joomla installation, I have got the needed SEF URL for author archive. But I lost all the permalinks in other places of my blog then.
Thus I had to return to the
http://www.yoursite.com?option=com_wordpress
for the ‘Home’ general option and make changes at the WordPress component core file.
It is not so critical to change core file of CorePHP-Wordpress component as CorePHP make updates not so often as original WordPress developers do :).
I changed the author-template.php file: at function get_author_posts_url() line

$link = get_option('home') . trailingslashit($link);

was changed to

$link = get_option('siteurl') .'/mobile-news'. trailingslashit($link);

Hurrah! I have got the SEF URL needed. But I met the new problem. That URL didn’t work. It redirected me to the home wordpress page (index.php) again and again. Additional investigation showed me that corePHP developers possibly missed this SEF URL type (www.yoursite.com/news/author/authorname) in their router.php script, so I had to add myself this code into function wordpressBuildRoute() just before the ‘default:’ option in the ‘switch’ operator:

      case $wp_rewrite->author_base:
        $sql = "SELECT ID
		FROM ".$table_prefix."users
		WHERE user_nicename='".$db->getEscaped($segments[1])."'
                    limit 0, 1";
        $db->setQuery($sql);
        $post = $db->loadAssoc();
        $vars['author'] = $post['ID'];
        //unset all of the used params
        for ($i=0;$i<=1;$i++) {
          unset($segments[$i]);
        }
        break;

That’s all. After that I have working SEF author archive links for CorePHP WordPress for Joomla component.
Thanks for reading,
Vladimir.

Tags: , ,

  • http://shinephp.com Vladimir Garagulya

    I guess that you use WordPress for Joomla. What version of WordPress for Joomla do you use?