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">›</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">›</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.
Print This Post
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
Ada simbol seperti ini pak
di ‘recent entries’ akan tampak sebuah judul postingan tapi dengan dua bahasa yg berbeda plus tampil dengan simbol-simbol seperti – ! > < =
mohn bantuannya ya pak… thq
bingung mau diapain
@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).
Sebelumnya terimakasih atas bantuannya ya,pak
Saya tidak ada basic ttg script, jadi ya trial and error gitu . hehehe…
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.
Hmmm, script yang saya kirim barusan tidak terbaca dan ketika di enter sebagian mengalami perubahan di halaman comment ini. T_T hiks
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