Please make sure to update to WPML 4.3.6 and check our list of Known Issues before reporting

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 24 replies, has 3 voices.

Last updated by sarah.n 6 years, 1 month ago.

Assigned support staff: sarah.n.

Author Posts
October 26, 2013 at 5:30 am #282484

Harshad

Dear Asa,

Did you remove the code, I supplied you earlier
http://wpml.org/forums/topic/blog-posts-to-display-all-posts-cpt-bug/#post-279474

November 11, 2013 at 10:39 am #289975

Asa

Sorry, but still without changes... 🙁

November 11, 2013 at 12:22 pm #290083

Harshad

Dear Asa,

I have enabled option for private details box, It will ask you for ftp and wordpress admin details.
Can you please fill in the information which will help me to investigate your issue.

November 18, 2013 at 10:27 am #293867

Asa

Hi Harshad,

I'm sending FTP access.
Testing templates are category-test.php and category-test2.php.

November 19, 2013 at 12:32 pm #294713

Harshad

Dear Asa,

Before moving further can you please upgrade WPML and addon plugins to latest version 3.0.1?
If you prefer however to do a manual update please follow these steps:

1. Backup your database – see for example: http://wordpress.org/extend/plugins/wp-db-backup/

2. Deactivate the existing WPML plugin and add-ons.

3. Delete the plugin files – this does not delete your translations. You will simply delete the plugin files from you "wp-content/plugins" folder NOT the database records.

4. Download the updated plugins from our servers and upload them to the plugin directory.

5. Activate the WPML plugin and add-ons.

December 4, 2013 at 10:11 am #302119

Asa

Thanks Harshad. But still not work correctly.
I have active option "All posts (display translation if it exists or posts in default language otherwise)." and here hidden link should be posts "One, Zwei, Drei", but "One" is missing

December 4, 2013 at 2:13 pm #302301

Harshad

Dear Asa,

Which is the actual template file, category-test.php or category-test2.php.

December 19, 2013 at 10:55 am #310858

Asa

Hi Harshad,

both are actual, but in category-test.php is tag in arguments.
We need to make it work for tags.

Thanks

December 20, 2013 at 4:49 pm #311625

Harshad

Dear Asa,

Sorry for delay, I will forward this issue to our Support Team leader Sarah

She should get back to you on your issue(s) asap.

Please standby for further updates.

December 23, 2013 at 10:39 am #312313

sarah.n
Supporter

Languages: English (English ) German (Deutsch )

Hello Asa,

This is Sarah here. Harshad forwarded your forum thread to me so I will do my best to assist you further.

What you basically need is to tell WPML to fetch the posts in the default language first.
Then you check if a translation exists and if it does you display the translation, if it does not you continue to display the default language post.

The code that follows shows this basic logic. The output is very simple (displays only the title) just to demonstrate that you end up with the expected result. You will have to modify the query arguments and output code to fit your needs.

global $sitepress;
// save current language
$current_lang = $sitepress->get_current_language();
//get the default language
$default_lang = $sitepress->get_default_language();
//fetch posts in default language
$sitepress->switch_lang($default_lang);
//query args
$custom_query_args = array(
    'cat' => 1
);
//build query
$custom_query = new wp_query($custom_query_args);
//loop
while ( $custom_query->have_posts() ) : $custom_query->the_post();
    //check if a translation exist
    $t_post_id = icl_object_id($post->ID, 'post', false, $current_lang);
    if(!is_null($t_post_id)){
        $t_post = get_post( $t_post_id);
    ?>
        <a href="<?php echo get_permalink($t_post_id); ?>" title="<?php echo get_the_title($t_post_id); ?>"><?php echo get_the_title($t_post_id); ?></a>
        <?php
    }
    //no translation? display default language
    else{ ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        <?php
    }  
endwhile;
wp_reset_query();
$sitepress->switch_lang($current_lang);

I added a modified version of your code inside your "category-test.php" template so you can see it in action. You have not lost the code of your original "category-test.php" template; it is still there under the template: "original_category-test.php"

This is what it looks like in your particular case:

// WPML Support
global $sitepress;
// save current language
$current_lang = $sitepress->get_current_language();
//get the default language
$default_lang = $sitepress->get_default_language();
//fetch posts in default language
$sitepress->switch_lang($default_lang);
//\ WPML Support

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args =	array( 
		'posts_per_page'   => 15, 
		'post_status'      => 'publish',
		'post_type'        => array('people'), 
		'orderby'          => 'date', 
		'paged'            => $paged, 
		'order'            => 'DESC',
		'tag__in' 			=> 4 // tag ID must be the original!
	);

$posts = new WP_Query( $args );
?>

	<div id="primary" class="content-area">
		<div id="content" class="site-content" role="main">

		<?php if ( $posts->have_posts() ) : ?>
			<header class="archive-header">
				<h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'twentythirteen' ), single_cat_title( '', false ) ); ?></h1>

				<?php if ( category_description() ) : // Show an optional category description ?>
				<div class="archive-meta"><?php echo category_description(); ?></div>
				<?php endif; ?>
			</header><!-- .archive-header -->

			<?php /* The loop */ ?>
			<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
			
			<?php
			// WPML Support			
			//check if a translation exist
			$t_post_id = icl_object_id($post->ID, 'people', false, $current_lang);
			if(!is_null($t_post_id)){
			$t_post = get_post( $t_post_id);
			?>
			<a href="<?php echo get_permalink($t_post_id); ?>" title="<?php echo get_the_title($t_post_id); ?>"><?php echo get_the_title($t_post_id); ?></a>
			<?php
			}
			//no translation? display default language
			else{ ?>
					<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
			<?php
			}
			//\ WPML Support
			?>
			
				<?php //get_template_part( 'content', get_post_format() ); ?>
			<?php endwhile; ?>
			
			<?php
			// WPML Support
			wp_reset_query();
			$sitepress->switch_lang($current_lang);
			//\ WPML Support
			?>

Please also note that in order for both the original and the translated category can use the same template I added the following function in your theme's functions.php file:

//WPML Support
/**
 * Redirect both the original category and the translation to the same category template
 */
function wpml_cat_redirect() {
    $cat = get_query_var('cat');
	// if current cat is 4 or 5
	if ( $cat == 3 ||  $cat == 5) {
		return get_template_directory() . '/category-test.php';
	}
}
add_action( 'category_template', 'wpml_cat_redirect' );
//\ WPML Support

Hope this helps.

P.S. Please keep in mind that any further modifications you may need help with the above such as assistance with the output code, falls under custom work and is not within the scope of the support we offer here in the forum.

The topic ‘[Closed] Blog posts to display – All posts (….) – CPT bug’ is closed to new replies.