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
URL instead of search engine friendly (SEF) permalink. In order to change that I use the way I was found at
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%';

At this stage I have got such URL as
But I needed more search engine friendly URL such as
After source code investigation I discovered that
goes from WordPress ‘home’ option (General Settings) where we have this
When I simply changed this URL to the
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
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";
        $post = $db->loadAssoc();
        $vars['author'] = $post['ID'];
        //unset all of the used params
        for ($i=0;$i<=1;$i++) {

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

Tags: , ,