WordPress.org

Forums

Flexible Recent Posts
[resolved] Basic support for polylang (2 posts)

  1. QuickeneR
    Member
    Posted 2 years ago #

    Polylang is one of the plugins that add to a WordPress blog the multilingual capability. Have translations of posts, pages, etc. Unfortunately, FRP does not filter posts by language and thus can show post excerpts in a different language than the rest of the blog.
    Here is a patch that allows to select languages by typing their slugs.

    --- templates/recent-posts-form.php.org2	2012-07-25 14:04:31.000000000 +0600
    +++ templates/recent-posts-form.php	2012-10-09 15:10:49.000000000 +0600
    @@ -47,6 +47,15 @@
     	<label
     		for="<?php print $this->get_field_id( 'all_posts_link_footer' ); ?>"><?php print __( 'Show after all posts', 'frp' ); ?></label>
     </p>
    +<p>
    +	<label for="<?php print $this->get_field_id( 'language_filter' ); ?>"><?php print __( 'Filter posts by language(s)' ); ?>:</label>
    +	<img src="<?php print $plugin_dir . 'images/help.png'; ?>"
    +		 title="<?php _e( 'Filter posts by language. Use the form \'en\' or \'en,ru\' for multiple languages. The list of valid languages is in Settings - Languages. Requires Polylang plugin', 'frp' ); ?>"
    +		 class="frp-form-help" alt="<?php _e( 'Help', 'frp' ); ?>">
    +	<input class="widefat" id="<?php print $this->get_field_id( 'language_filter' ); ?>"
    +		   name="<?php print $this->get_field_name( 'language_filter' ); ?>"
    +		   value="<?php print $instance['language_filter']; ?>" type="text">
    +</p>
     <h4 class="frp-form-group-title"><?php print __( 'Categories' ); ?><img
     	src="<?php print $plugin_dir . 'images/help.png'; ?>" title="<?php _e( 'Posts categories', 'frp' ); ?>"
     	class="frp-form-help" alt="<?php _e( 'Help', 'frp' ); ?>"></h4>
    
    --- class-recent-posts-widget.php.org2	2012-07-25 14:00:57.000000000 +0600
    +++ class-recent-posts-widget.php	2012-10-09 15:09:25.000000000 +0600
    @@ -38,7 +38,8 @@
     				'template'                  => '',
     				'theme'				=> 'default',
     				'all_categories'            => true,
    -				'categories'                => array()
    +				'categories'                => array(),
    +				'language_filter'           => ''
     			)
     		);
    
    @@ -71,12 +72,16 @@
     		$instance['all_posts_title'] = htmlspecialchars( $instance['all_posts_title'] );
    
     		if ( !empty( $instance['categories'] ) || $instance['all_categories'] ) {
    -			$posts = get_posts(
    -				array(
    -					'numberposts' => $instance['number'],
    -					'category'    => implode( ',', $instance['categories'] ),
    -				)
    +			$posts_query = 	array(
    +				'numberposts' => $instance['number'],
    +				'category'    => implode( ',', $instance['categories'] ),
     			);
    +			# Only add the language filter if Polylang is installed
    +			if ( function_exists('pll_the_languages') ) {
    +			    $posts_query['lang'] = $instance['language_filter'];
    +			}
    +
    +			$posts = get_posts($posts_query);
    
     			if ( !empty( $posts ) ) {
     				$category_link = ( empty( $instance['all_posts_link'] ) ) ? get_category_link( end( $instance['categories'] ) ) : $instance['all_posts_link'];
    @@ -103,6 +108,7 @@
     		$instance['all_posts_link_title'] = isset( $new_instance['all_posts_link_title'] ) ? true : false;
     		$instance['all_posts_link_footer'] = isset( $new_instance['all_posts_link_footer'] ) ? true : false;
     		$instance['all_posts_title'] = strip_tags( $new_instance['all_posts_title'] );
    +		$instance['language_filter'] = strip_tags( $new_instance['language_filter'] );
     		$instance['all_posts_link'] = '';

    http://wordpress.org/extend/plugins/flexible-recent-posts/

  2. Paul Annekov
    Member
    Plugin Author

    Posted 2 years ago #

    qTranslate plugin must work perfectly without any plugins :).
    I will add filters to FRP, so you can create yor own plugin, that will add integration with Polylang. I think, that hardcoding usage of other plugins is not good. There are more plugins for multilingual blog and I can't hardcode integration with each of them. So it's another plugin's job.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Flexible Recent Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.