WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Display content in specific language outside wordpress (2 posts)

  1. mountain_spring
    Member
    Posted 1 year ago #

    Hello,

    Before I've installed polylang, I've used following code to display latest topics on my site index page which is outside wordpress.

    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('blog/wp-load.php');
    ?>
    
    <?php
    $posts = get_posts('numberposts=4&order=DSC&orderby=post_title');
    foreach ($posts as $post) : start_wp(); ?>
    <h6 class="datum"><?php the_date(); echo "<br />"; ?></h6>
    <h2 class="naslov"><?php the_title(); ?></h2>
    <div class="entry-content"><a class="blognaslov" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">Read More</a><br><br></div>
    <?php
    endforeach;
    ?>

    It still works, but displays post in both languages that I use.
    Is it possible to display only posts in one of the languages.

    I've found this in polylang documentation (p.12), but it doesen't work.

    $posts = get_posts(array(
    'post_type' => 'post',
    'lang' => 'fr', // use language slug in the query
    'showposts' => 5
    ));

    And Second question, is it possible to display links to pages outside wordpress that are added in header.php in language that is currently active?

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

    [ Please do not bump, that's not permitted here. ]

  2. mountain_spring
    Member
    Posted 1 year ago #

    Ok, I got it by altering:

    $posts = get_posts('numberposts=4&order=DSC&orderby=post_title');

    to

    $posts = get_posts('numberposts=4&order=DSC&orderby=post_title&lang=hr');

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags