Home > WordPress > Adjust MicroKid Related Posts v2.3 with qTranslate v2.4.3 Plugins

Adjust MicroKid Related Posts v2.3 with qTranslate v2.4.3 Plugins

I have been using qTranslate plugins for the last two days. I love this plugins so much since it is a simple plugins, yet easy to use and also has the powerful feature until now, especially when I edit or add the new post. Simply click the tab regarding to the language you want. If I compare with the other translate plugins, qTranslate is still the best, at least for me.

Today I started to use MicroKid Related Posts plugins for displaying the Related Posts at the bottom of the post. Unfortunately, I found a little bit problem after I have succeeded to implement this plugins. What was that? Well, since the post title has been saved by qTranslate plugins in one field in wp_posts table for all active languages, then each time the post title displayed, it contains of the title post belong to those all languages, and there is no space between them.

For example: I already have a post with title in English “Welcome to My World” whereas in Indonesian language this has the meaning as “Selamat datang di Dunia Saya”. For those of you who has not tried this plugins, the value for the post_title field would be like this:

<!--:en-->Welcome to My World<!--:--><!--:id-->Selamat datang di Dunia Saya<!--:-->

that is why when it displayed the result will become like this:

Welcome to My WorldSelamat datang di Dunia Saya

whereas between one title with another belongs to other language does not separated by space character, and I think this is something that looks like not so good.

When I search this post and then select this post title as related post for my new post, then the title of this related post will become: “Welcome to My WorldSelamat datang di Dunia Saya”. As you can see, that post_title being shown contains of the both active language; English and Indonesian. I think it would be better if it should be like this:

Welcome to My World if the selected language is English,
or:
Selamat datang di Dunia Saya is the selected language is Indonesian.

This is an interested challenge for me. So I started to search the script related to this, and trying to make it came true.

So, here was I made:

1. Open mrp-search.php file belongs to MicroKid Related Posts plugins, and find this code:

55
foreach( $results as $result ) {

then replace with this:

55
56
foreach( $results as $result ) {
  $related_post_title = wp_specialchars(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($result->post_title));

also, find this code:

63
64
echo $result->post_title.'</a> <a href="'.get_permalink( $result->ID ).'"
     title="View this post" target="_blank">&rsaquo;</a></li>';

and replace with this:

63
64
echo $related_post_title.'</a> <a href="'.get_permalink( $result->ID ).'"
     title="View this post" target="_blank">&rsaquo;</a></li>';

We have done with the mrp-search.php file.

2. The next step is that we have to edit the code in microkids-related-posts.php file.
Open the file and find this code:

95
foreach( $related_posts as $related_post_id => $related_post_title ) {

replace with this:

95
96
foreach( $related_posts as $related_post_id => $related_post_title ) {
  $related_post_title = wp_specialchars(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($related_post_title));

also, find this code:

317
foreach( $related_posts as $related_post_id => $related_post_title  ) {

and replace with this:

317
318
foreach( $related_posts as $related_post_id => $related_post_title  ) {
  $related_post_title = wp_specialchars(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($related_post_title));

then, find also this code:

367
foreach( $related_posts as $related_post_id => $related_post_title  ) {

and replace with this code:

367
368
foreach( $related_posts as $related_post_id => $related_post_title  ) {
  $related_post_title = wp_specialchars(qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($related_post_title));

That’s all. Now the title post in Related Posts section will look better than before. You can see the result in the bottom of this post at the Related Posts section, when you display a post with full-mode.

This has been tested and working good in MicroKid Related Posts version 2.3 and qTranslate version 2.4.3.

  • Share/Bookmark
302 views Print This Post Print This Post