Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

qTranslate home url & breadcrumbs not working in second language WordPress

  • SOLVED

Hi,
I'm using qTranslate with Suffusion. Home url and breadcrumbs don't work for second language (fine in posts but not for pages).
I did a workaround for the navigation bar so that's ok.
I presume I need some code tweaked to fix 1. logo in second language should link to homepage in that language. 2. Breadcrumb 'home' link to link to second language homepage.

I'm not a programmer but I presume it's somewhere in my actions.php and breadcrumb-page.php files.
Here's (what I think is!) relevant part of actions.php:
<?php
}
}
function suffusion_home_url() {
$home_link = home_url();
if (function_exists('icl_get_home_url')) {
$home_link = icl_get_home_url();
} else if (function_exists('qtrans_getLanguage')) {
$home_link .= '/'.qtrans_getLanguage().'/';
}
return $home_link;
}

function suffusion_display_header() {
global $suf_sub_header_vertical_alignment, $suf_header_fg_image_type, $suf_header_fg_image, $suf_header_alignment, $suf_sub_header_alignment;
$display = apply_filters('suffusion_can_display_header', true);
if (!$display) {
return;
}
if ($suf_header_alignment == 'right') {
suffusion_display_widgets_in_header();
}
if (!is_singular() || is_page_template('magazine.php')) {
$header_tag = "h1";
}
else {
$header_tag = "h2";
}
?>
<header id="header" class="fix">
<?php
$header = ($suf_header_fg_image_type == 'image' && trim($suf_header_fg_image) != '') ? "<img src='$suf_header_fg_image' alt='".esc_attr(get_bloginfo('name'))."'/>" : get_bloginfo('name', 'display');
$home_link = suffusion_home_url();
$description_qtranslate = html_entity_decode(get_bloginfo('description', 'raw'));
if ($suf_sub_header_vertical_alignment == "above") {
?>
<div class="description <?php echo $suf_sub_header_alignment; ?>"><?php _e($description_qtranslate);?></div>
<<?php echo $header_tag?> class="blogtitle <?php echo $suf_header_alignment; ?>"><a href="<?php echo $home_link;?>"><?php echo $header;?></a></<?php echo $header_tag?>>
<?php
}
else {
?>
<<?php echo $header_tag?> class="blogtitle <?php echo $suf_header_alignment; ?>"><a href="<?php echo $home_link;?>"><?php echo $header;?></a></<?php echo $header_tag?>>
<div class="description <?php echo $suf_sub_header_alignment; ?>"><?php _e($description_qtranslate);?></div>
<?php
}
?>
</header>


breadcrumbs-page.php:
<?php
/**
* Shows the breadcrumb for anything for pages based on the following algorithm:
* - It can print a full hierarchy of ancestors, siblings and immediate children, if the breadcrumb is set to display everything.
* - It can print a regular breadcrumb if set appropriately.
* A home link/icon is optionally shown.
*
* @since 3.8.3
* @package Suffusion
* @subpackage Custom
*/

global $post, $suf_nav_breadcrumb, $suf_nav_exclude_in_breadcrumb, $suf_breadcrumb_separator, $suf_show_home_in;
$toggle = suffusion_get_post_meta($post->ID, 'suf_toggle_breadcrumb');
if ($suf_nav_breadcrumb == "none" && !$toggle) {
return;
}
else if ($suf_nav_breadcrumb != "none" && $toggle) {
return;
}

if (!is_front_page() && !is_home() && is_page()) {
$ancestors = get_ancestors($post->ID, 'page');
$num_ancestors = count($ancestors);
if ($suf_nav_breadcrumb == "all") {
$display = apply_filters('suffusion_can_display_hierarchical_navigation', true);
if (!$display) {
return;
}

$exclusion_list = suffusion_get_excluded_pages("suf_nav_pages");
for ($anc_index = 1; $num_ancestors - $anc_index >= 0; $anc_index++) {
$style = ($anc_index == 1) ? "subnav" : "l".($anc_index + 1)."nav";
$class = ($anc_index == 1) ? "" : "hier-nav";
?>
<div id="<?php echo $style;?>" class="<?php echo $class; ?> fix">
<ul>
<?php suffusion_get_siblings_in_nav($ancestors, $num_ancestors - $anc_index, $exclusion_list, $suf_nav_exclude_in_breadcrumb); ?>
</ul>
</div><?php echo "<!-- /".$style."-->"; ?>
<?php
}
$exclusion_query = $suf_nav_exclude_in_breadcrumb == "hide" ? "&exclude_tree=".$exclusion_list : "";
$style = ($num_ancestors == 0) ? "subnav" : "l".($num_ancestors + 2)."nav";
$class = ($num_ancestors == 0) ? "" : "hier-nav";
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0".$exclusion_query);
if ($children) {
?>
<div id="<?php echo $style;?>" class="<?php echo $class; ?> fix">
<ul>
<?php echo $children; ?>
</ul>
</div><!-- /sub nav -->
<?php
}
}
else {
$display = apply_filters('suffusion_can_display_breadcrumb_navigation', true);
if (!$display) {
return;
}

$show_home = explode(',', $suf_show_home_in);
if ($num_ancestors > 0 || in_array('page', $show_home)) {
?>
<div id="subnav" class="fix">
<div class="breadcrumb">
<?php
if (in_array('page', $show_home)) {
echo "<a href='".home_url()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
for ($i = $num_ancestors-1; $i>=0; $i--) {
$anc_page = get_page($ancestors[$i]);
echo "<a href='".get_permalink($ancestors[$i])."'>".$anc_page->post_title."</a> ".$suf_breadcrumb_separator." ";
}
echo get_the_title();
?>
</div>
</div><!-- /sub nav -->
<?php
}
}
}
?>


my web page is:
http://www.mydog.ie/wordpress

Answers (1)

2013-07-25

Hariprasad Vijayan answers:

Hello,

Are you using only two languages?


Hariprasad Vijayan comments:

Replace the function suffusion_home_url() in actions.php with following function

function suffusion_home_url() {
$home_link = home_url();
if (function_exists('icl_get_home_url')) {
$home_link = icl_get_home_url();
} else if (function_exists('qtrans_getLanguage')) {
$home_link .= '/'.qtrans_getLanguage().'/';
}
if(qtrans_getLanguage()!='en')
{
return $home_link;
}
else
{
return $home_link .= $home_link.'/'.qtrans_getLanguage();
}

}

Hope the above code will correct logo url

Change the section

if (in_array('page', $show_home)) {

echo "<a href='".home_url()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";

}


displayed under <div class="breadcrumb"> in breadcrumbs-page.php with following code

if (in_array('page', $show_home)) {
if(qtrans_getLanguage()!='en')
{
echo "<a href='".home_url()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
else
{
echo "<a href='".home_url().'/'.qtrans_getLanguage()"'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
}


Hope this will solve the issue. Please ask if you have any doubt regarding this. Good luck


Hariprasad Vijayan comments:

There is a mistake in my code, code in actions.php should be as follows

function suffusion_home_url() {
$home_link = home_url();
if (function_exists('icl_get_home_url')) {
$home_link = icl_get_home_url();
} else if (function_exists('qtrans_getLanguage')) {
$home_link .= '/'.qtrans_getLanguage().'/';
}
if(qtrans_getLanguage() == 'en')
{
return $home_link;
}
else
{
return $home_link .= $home_link.'/'.qtrans_getLanguage();
}
}

and the code in breadcrumbs-page.php would be

if (in_array('page', $show_home)) {
if(qtrans_getLanguage() == 'en')
{
echo "<a href='".home_url()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
else
{
echo "<a href='".home_url().'/'.qtrans_getLanguage()"'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
}

Sorry for the mistake. Let me know if you have any trouble in this.


Ailsa Craig comments:

Hi,
Many thanks for your reply. Unfortunately the url still doesn't work.
I get a syntax error on this line
echo "<a href='".home_url().'/'.qtrans_getLanguage()"'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
in the breadcrumbs (any idea why?)
so when i upload that file nothing appears below my header.
Yes it's just the two languages (english default) and irish is the one I'm having problem with.


Hariprasad Vijayan comments:

Can you replace the code in breadcrumbs-page.php

if (in_array('page', $show_home)) {
if(qtrans_getLanguage() == 'en')
{
echo "<a href='".home_url()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
else
{

echo "<a href='".home_url()."/".qtrans_getLanguage()."'>".__('Home', 'suffusion')."</a> ".$suf_breadcrumb_separator." ";
}
}

Let me know is there is any error


Hariprasad Vijayan comments:

Can you show me the result of function qtrans_getLanguage() in both languages. Just use the following code to get result
echo qtrans_getLanguage();


Ailsa Craig comments:

Hariprasad - genius - the breadcrumbs work perfectly now thanks!

I put echo qtrans_getLanguage(); into the actions.php and nothing at all happens. In fact anything I edit there, nothing happens. I even stripped out all the code and just put your original suggestion in there and nothing. I'm using a child theme I wonder is the actions.php not overwriting original?
I found a template.php with reference to home link - maybe this should be changed too? Although I tried putting qtranslate in there and again nothing happens.


Hariprasad Vijayan comments:

Hi,

sorry for the delay.

let me know where the actions.php exists? is it in child theme or parent theme?
i think the code that i provided is right. but the actions.php should be in child theme if you are using a child theme.
can you please provide the credentials in PM.


Ailsa Craig comments:

Hi,
Yes actions.php is in exact same format as parent theme.
Parent theme is: suffusion/functions/actions.php
Child theme is: son-of-suffusion/functions/actions.php


Hariprasad Vijayan comments:

I didn't get exact reason of the error in actions.php. The code echo qtrans_getLanguage(); returns the current selected language and its working in breadcrumbs-page.php perfectly. And the same thing implemented in actions.php. There is something wrong with it. Are you sure the actions.php is working?


Hariprasad Vijayan comments:

Did you check actions.php is working correctly?


Ailsa Craig comments:

I found out actions.php is not a pluggable file - whatever that means. I guess it means anything I do there won't take effect!


Hariprasad Vijayan comments:

Yes. Can you please share the FTP creadentials in PM. Let me check whats wrong in it.


Ailsa Craig comments:

Perfect - solved now. Thanks so much for all your help Hariprasad


Hariprasad Vijayan comments:

You are always welcome...