Site logo

Archived topic

Post navigation language

9 replies · Started by Enrico on December 9, 2020

Viewing posts 1–10 of 10

Hi there.
I see just now that the post navigation does not work as I expected.
If you please have a look on this post you will see that the navigation shows my next/previous post in Italian language, and not my next/previous English post.
How can I fix?
Thank you

Hi there,

Sorry not sure if I fully understand.

So is this a translation issue?

Let me know :)

Leo,
probably you don't understand due to my bad English, I'm sorry...
It's so:
my blog has posts in Italian and in English, but just few Italian posts are translated in English.
I would like that in the English version the post navigation shows only the next/previous English post.
At the moment the navigation shows the posts (next/previous) in chronological order, regardless of the language.
But maybe this is not possible, I don't know...
Thank Leo.

Couple of questions, are you using a translation plugin? Is English and Italian categories by any chance?

Yes Leo, I'm using WPML.
All categories are translated.
Thanks.

I discover that using the main theme (not a child theme) the issue disappears.
But if I use the child theme, without any custom css, the issue is still there...

Hi there,

I wonder if this is a setting in WPML - have you checked with their support to see if they have any ideas?

Hi Tom.
I found the code that causes the issue.
In functions.php file I added the following code, because I need to have tag in pages too.
This is the code:

function add_taxonomies_to_pages() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'add_taxonomies_to_pages' );
if ( ! is_admin() ) {
add_action( 'pre_get_posts', 'category_and_tag_archives' );
}
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');

if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
$wp_query->set( 'post_type', $my_post_array );

if ( $wp_query->get( 'tag' ) )
$wp_query->set( 'post_type', $my_post_array );
}

Do you think is possible to mantain my custom code and also fix the issue?
Thanks a lot.
Enrico

I'm sorry to be again here, but I think I solve, so I will close this ticket.
Instead that edit functions.php I added a snippet, and it seems it works well.
I add this:

function add_taxonomies_to_pages() {
 register_taxonomy_for_object_type( 'post_tag', 'page' );
 register_taxonomy_for_object_type( 'category', 'page' );
 }
add_action( 'init', 'add_taxonomies_to_pages' );

Thank you.
Enrico

Glad you've found the solution and thanks for reporting back!

This archived topic is closed to new replies.