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
491 views Print This Post Print This Post

  1. June 12th, 2010 at 18:00 | #1

    Hallo Pak… mohon bantuannya ^_^
    Kenapa ya saya mengalami hal yang sama setelah menginstall qtranslate? post title tetap ditampilkan sesuai dengan yang diinginkan pada setiap posting baik english atau arab, tak ada masalah. Namun di “recent entries” (terletak di bagian kiri atas dr blog saya) post title tampil seperti ini :
    Welcome to My WorldSelamat datang di Dunia Saya

    bagaimana cara penyelesaiannya ya pak? sudah utak/tik sana sini tapi ga bisa juga…
    mohon bantuan. terimakasih sebelumnya :)

  2. June 12th, 2010 at 18:03 | #2

    Ada simbol seperti ini pak

  3. June 12th, 2010 at 18:09 | #3

    di ‘recent entries’ akan tampak sebuah judul postingan tapi dengan dua bahasa yg berbeda plus tampil dengan simbol-simbol seperti – ! > < =
    bingung mau diapain :D mohn bantuannya ya pak… thq

  4. June 12th, 2010 at 19:19 | #4

    @nafuzu

    Kemungkinan “Recent Entries” tersebut menggunakan kode yang terdapat di theme yang Anda gunakan, dan harus dimodifikasi lagi dengan cara menambahkan function “qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage()” seperti langkah-langkah di artikel ini.

    Contoh penggunaan:
    qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_title)
    di mana $post_title merupakan variabel yang menampilkan data judul tulisan (sesuaikan dengan yang digunakan di theme Anda).

  5. June 13th, 2010 at 11:36 | #5

    Sebelumnya terimakasih atas bantuannya ya,pak :) Saya tidak ada basic ttg script, jadi ya trial and error gitu . hehehe… :D

    theme website saya dapatkan di http://wpjunction.com/starcad/
    Pak…Dimana ya saya harus menambahkan qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_title) ?

    di bagian index.php saya menemukan script di bawah ini, di bagian mana saya harus ganti? Atau di file php yang lain?

    Recent Entries

    Popular Posts

    Recent Comments

    <div id="post-” class=”post”>

    Categorized under

    <a href="” title=”">

    <?php wp_pagenavi('’, ‘‘) ?>

    Not Found

    Sorry, but you are looking for something that isn’t here.

  6. June 13th, 2010 at 11:39 | #6

    Hmmm, script yang saya kirim barusan tidak terbaca dan ketika di enter sebagian mengalami perubahan di halaman comment ini. T_T hiks

  7. June 13th, 2010 at 21:31 | #7

    Syukurlah setelah utak/ik seharian ini, semuanya dah berjalan sesuai dengan yang diinginkan. Ternyata tinggal menambahkan tanda __ di bagian plugin.php menjadi
    foreach ($posts as $post) {
    $post_title = __($post->post_title);

    saya baca di http://www.bravenewcode.com/support/topic/wptouch-and-qtranslate
    coba-coba aplikasikan perubahan tanda __ di plugin.php dari theme saya..

    Ok ,pak masino …thank u so much ya ;) salam kenal

  1. August 30th, 2009 at 21:21 | #1
  2. September 7th, 2009 at 17:46 | #2