WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Translations on homepage (20 posts)

  1. Siroj
    Member
    Posted 1 year ago #

    I'm using polulang and i use a homepage that shows posts from a specific category.

    What do i have to do to get the homepage of the second language to show the posts only from the corresponding category.

    I tried something like this before the loop:

    <?php if (!is_paged() and is_home()) {
    query_posts('&cat=4,34');

    } ?>

    where 4 is the category for the default language and 34 for the second.

    Greetings,
    Joris

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Is it a static front page with a specific template ?

  3. Siroj
    Member
    Posted 1 year ago #

    Hi Chouby,

    no, it is a frontpage with intro's from a specific category. I use http://standardtheme.com the standard theme.

    I had to change it a bit for getting the intro to work and to get only intro's from a specific category.

  4. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    what was the code before you modified it ?
    In your code, before your category $cat is used, just do this

    $cat = pll_get_term($cat); // does the category translation if necessary
  5. Siroj
    Member
    Posted 1 year ago #

    I used different kind of codes.

    The kind i posted above didn't work, also not with you addition.

    To get only intro-articles from category 4 (dutch homepage-articles) on the homepage i use this code now:

    <?php if ( is_front_page() ) {
          $cat = pll_get_term($cat);
    	  query_posts('&cat=4'); 
    
    } // end if ?>

    That works for the dutch part. But when i click on german it shows the same articles, articles from category 4, then it should show articles from cat 34.

    There wasn't any code in the template for showing specific articles on the frontpage. Thats why i added the code in the first place.

    I tried a lot od snippets i found using search, but none worked, some showed me all latest posts in German. But i want only to show from a specific category.

    is there a setting or specific way i have to use for the 'homepage' in the menu? Hoe does Wordress now its the homepage in another language?

    I use a link to the root of the site as the 'homepage'....

    So i would think i needed somethink like

    <?php if ( is_front_page() && code for language == nl_NL ){
           $cat = pll_get_term($cat);
    	  query_posts('&cat=4'); 
    
    } // end if ?>

    and the same snippet for german with de_DE and cat=34

  6. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Does this work ?
    query_posts('cat='.pll_get_term(4));
    instead of
    query_posts('&cat=4');

  7. Siroj
    Member
    Posted 1 year ago #

    :-) Thanks...

    That did the trick! Really need to dive into php :-)

  8. Siroj
    Member
    Posted 1 year ago #

    Hi,

    the code worked, but i later noticed that the link to older en newer posts didn't work. They just showed the homepage-posts again.

    So i searched for solutions.

    I found one that worked on the default language homepage. But when i change the language it doesn't.

    I fiddled around with the code but i lack php-skills...

    Maybe its just something small... I tried something like this.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=.pll_get_term(4&paged=$paged)");;

    Maybe someone sees an obvious mistake...

  9. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Maybe like this ?

    query_posts('cat='.pll_get_term(4).'&paged='.$paged);
  10. Siroj
    Member
    Posted 1 year ago #

    Thanks again!

    That works. Newer and older posts now work in the other languages :-)

  11. puzzlegym
    Member
    Posted 1 year ago #

    I have a similar problem I think
    I'm using polylang and I use a homepage that shows posts from a specific category too. For this I have the following code in Main Index template:

    <?php if (is_home())
    {
    query_posts("category_name='puzzlenews'");
    }
    ?>
    Currently the homepage shows posts in default language. How do I get the second language (English) homepage to list posts in English?

  12. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Could you try to copy / paste http://pastebin.com/utLLn1cu in a php file, upload it in your plugins directory and activate the newly created plugin?

  13. puzzlegym
    Member
    Posted 1 year ago #

    Unfortunately it triggers an error:

    Plugin could not be activated because it triggered a fatal erro

    r

    Parse error: syntax error, unexpected T_FUNCTION in /home/artistic/public_html/wp-content/plugins/auto translate for Polylang.php on line 18

  14. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Ooops. You probably use a php version older than 5.3... I modified the code. Could you try again?

  15. puzzlegym
    Member
    Posted 1 year ago #

    It generated a warning

    The plugin generated 4 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

    and later the "headers already sent” error.

    The site uses WordPress 5.3.1

    Here is the link if it helps
    http://puzzlegym.ro/ro/

    Thanks for prompt replies.

  16. puzzlegym
    Member
    Posted 1 year ago #

    Would you have any other ideas for this problem? Thank you.

  17. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    It's hard to know why you got this error (and not me...). But I updated the file again, corrected some bugs and it was since successfully tested by another person than me. So you can test it again if you want.

    Otherwise, you can try to replace your code by:

    <?php if (is_home())
    {
    	$slug = 'puzzlenews';
    	if (($cat = get_category_by_slug($slug)) && ($tr_id = pll_get_term($cat->term_id)) && !is_wp_error($tr = get_category($tr_id)))
    		$slug = $tr->slug;
    	query_posts("category_name=$slug");
    }
    ?>

    In that case, the best is to make a child theme.

  18. puzzlegym
    Member
    Posted 1 year ago #

    Thanks so much. The code worked! It's great! :)

  19. ldeddens
    Member
    Posted 1 year ago #

    Hi,
    I also use polylang and I have 'inspire' wpo theme.
    Translation all works great but I would like to default show post in corresponding langiage on home. So on german it takes post from german news, in french from french news and in english from english news. It does show the correct category links on the homepages. Fopr example here http://194.150.248.140/~volvoar1/en/ you have 'show all' and 'news en'. What I want is it default to open/show my news en post. Now you have to click it to see them.

    In my index I have this code:

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <!-- FILTER MENU -->
    		<?php get_template_part('inc/templates/template_filter_menu'); ?>
    
    and the filter menu code is:
    		<div id="filter"
    			data-page_type="<?php echo mb_get_page_type(); ?>"
    			data-category="Show all"
    			data-subfilter="Latest"
    			data-current_page="1"
    			data-more_posts="true"
    			data-search_query="<?php echo get_search_query(); ?>"
    			data-author_ID=""
    			data-tag=""
    		>
    
    			<ul id="filter_category">
    			<?php 
    
    				//build include string
    				$inspire_options_hp = get_option('inspire_options_hp');
    				$include_string = " ";
    
    				if (!empty($inspire_options_hp['cat_ID'])) {
    					foreach ($inspire_options_hp["cat_ID"] as $key => $value) {
    						$include_string .= 	$key . ",";
    					}
    					$include_string = substr($include_string,0,strlen($include_string)-1);
    				} 
    
    				wp_list_categories(array(
    					'show_option_all' => __("Show all", "loc_inspire"),
    					'include' => $include_string,
    					'title_li' => ""
    
    				));
    			?>
    
    <li>
     					<div id="loading-image"><img src="<?php echo get_template_directory_uri(); ?>/images/ajax-loader.gif"></div>
    				</li>
    			<ul id="filter_subfilter" class="sort">
    
    <li><a href="#"><?php _e('Latest', 'loc_inspire'); ?></a></li>
    <li><a href="#"><?php _e('Likes', 'loc_inspire'); ?></a></li>
    				<li class="last"><a href="#"><?php _e('Comments', 'loc_inspire'); ?></a>
    
    		</div>

    Anybody an idea how i can make english post open default on english home in stead of show all? (and french on french etc) Thanks a lot for any help!!

  20. @ldeddens Could you please start your own topic instead? This one has been marked resolved.

    http://wordpress.org/support/plugin/polylang#postform

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags