WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Querying page – how to display page excerpt in the correct language

[Resolved] Querying page – how to display page excerpt in the correct language

  • Hello,

    First off, I think Polylang is brilliant. I am using it to develop GĂ idhlig language websites.

    I have pretty permalinks enabled and am running a static homepage on a custom template. All is working well. Apart from one thing.

    I am using the following code to publish the excerpt of the “about us” page on the static homepage. It is working perfectly in English, because I am querying that exact page. However, I can’t work out how to write the query in order to pull the extract of the page depending on which language is selected. The ID of the gd page is 26. I guess I am missing something obvious, but I have no idea what it is.

    Thanks in advance

    <?php query_posts( 'page_id=27' );?>
        <?php while ( have_posts() ) : the_post(); ?>
            <p><?php the_excerpt(); ?></p>
    		<p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >>></a></p>
        <?php endwhile; ?>
    <?php wp_reset_query(); ?>

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chouby

    @chouby

    You have at least two choices:

    $page_id = pll_current_language() == 'gd' ? 26 : 27;

    or:

    $page_id = pll_get_post(27); // automatically gets the right translation

    don’t forget to test if functions exists (in case Polylang is deactivated).

    Wow! Thank you for the quick response.

    So, I now have

    <?php query_posts( $page_id = pll_get_post(27)) ;?>	
    
        <?php while ( have_posts() ) : the_post(); ?>
            <p><?php the_excerpt(); ?></p>
    		<p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >>></a></p>
        <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    Which is pulling the correct language, but not page id 27 – in fact it is pulling all posts…

    I checked that the function existed.

    Apologies. Getting into functions in this depth is new to me…

    Plugin Author Chouby

    @chouby

    In fact, you should write:

    query_posts( 'page_id=' . pll_get_post(27));

    Superb. That’s it! Thank you very much for your help. I hope this plugin goes from strength to strength – it deserves to!

    Code in case anyone else has the same issue:

    <?php query_posts( 'page_id=' . pll_get_post(27));?>	
    
        <?php while ( have_posts() ) : the_post(); ?>
            <p><?php the_excerpt(); ?></p>
    		<p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >>></a></p>
        <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    Thank you Wodleskodie for your feedback and Chouby to help!
    I needed this function to display the content of a post and it works perfectly.
    Yes, Polylang is a great plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Querying page – how to display page excerpt in the correct language’ is closed to new replies.