Some more Bugfixing for qtranslate slug

Hey Again.

As my previous blog post seems to have helped some people, i post another little bugfix for qtranslate slug i just encountered.

Before that, some information:
In this case, we talk about a newly installed WordPress 3.5.1, a reduced „twenty-twelve“ as theme and qtranslate 2.5.34 / qtranslate slug 1.1 environment. I have no idea, if the bug occurs on previous versions of WordPress, but i think it should (right now i’m too lazy to test it).

As many others, i use a dropdown-menu which (as i have installed qtranslate / qtranslate slug) should be translated. Also i need to use the global $post before the loop starts, e.g. for echoing the post thumbnail in the header.

I found that on every page i displayed, the post thumbnail of the last item in my dropdown was displayed instead of the actual thumbnail of the page i was on.

Why is that? I found that in the function _get_page_link of qtranslate slug, the global $post variable is used without resetting it to the value it was before. SOOOO here is the fix:

– Open the qtranslate-slug.php (which you should find in the folder wp-content/plugins/qtranslate-slug )
– go to line 1293 and find the public function _get_page_link( $link, $id )
– mark everything until the end of the function (around line 1319 , ends with

return $link;

– Replace it with the following code:

public function _get_page_link( $link, $id ) {
global $post, $wp_rewrite, $q_config;
// Begin Changes: Add temp var for our original post object
$tmp_post = $post;
// End Changes
if ( !$id )
$id = (int) $post->ID;
$post = &get_post($id);

$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );

$link = $wp_rewrite->get_page_permastruct();

if ( !empty($link) && ( isset($post->post_status) && !$draft_or_pending ) ) {

$link = str_replace('%pagename%', $this->get_page_uri($id), $link);

$link = trim($link, '/'); // hack
$link = home_url("/$link/"); // hack

if ($q_config['url_mode'] != 1)
$link = user_trailingslashit($link, 'page');

} else {

$link = home_url("?page_id=$id");
// Begin Changes: set the global $post back to the original stored in $tmp_post
$post = $tmp_post;
// End Changes
return $link;

Et Voila! No more getting the wrong Post Thumbnail (or other $post related stuff before the loop) just by having a menu!

I hope these changes help somebody, if not, just ignore it ^^ 😉

Kuchen und Kakao


Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )


Verbinde mit %s