Title: Widget Category Posts
Last modified: August 21, 2016

---

# Widget Category Posts

 *  [femetal](https://wordpress.org/support/users/femetal/)
 * (@femetal)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/widget-category-posts/)
 * Hi,
 * I have WP 3.7.1 with the premium template WP-ClearVideo by Solostream.
 * I also have installed Ceceppa (last version).
 * The template came eith some widget, one of them is category posts page, which
   create a widget with the last X posts/pages of a determinate category.
 * I post the code of that widget:
 *     ```
       /*-----------------------------------------------------------------------------------*/
       // This starts the Category Posts widget.
       /*-----------------------------------------------------------------------------------*/
   
       add_action( 'widgets_init', 'catposts_load_widgets' );
   
       function catposts_load_widgets() {
       	register_widget( 'Catposts_Widget' );
       }
   
       class Catposts_Widget extends WP_Widget {
   
       	function Catposts_Widget() {
       		/* Widget settings. */
       		$widget_ops = array( 'classname' => 'catposts', 'description' => __('Adds posts from a specific category .', "solostream") );
       		/* Widget control settings. */
       		$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'catposts-widget' );
       		/* Create the widget. */
       		$this->WP_Widget( 'catposts-widget', __('Category Posts Widget', "solostream"), $widget_ops, $control_ops );
       	}
   
       	function widget( $args, $instance ) {
       		global $post;
       		$post_old = $post; // Save the post object.
   
       		extract( $args );
   
       		// If no title, use the name of the category.
       		if( !$instance["title"] ) {
       			$category_info = get_category($instance["cat"]);
       			$instance["title"] = $category_info->name;
       		}
   
       		// Get array of post info.
       		$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&post_type=any");
   
       		/* Before widget (defined by themes). */
       		echo $before_widget;
   
       		// Widget title
       		echo $before_title;
       		if( $instance["title_link"] )
       			echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
       		else
       			echo $instance["title"];
       		echo $after_title;
   
       		// Post list
       		echo "<div class='cat-posts-widget textwidget'>\n";
   
       		while ( $cat_posts->have_posts() )
       		{
       			$cat_posts->the_post();
       		?>
       				<div class="post">
   
       					<div class="entry clearfix">
   
       						<a href="<?php the_permalink() ?>" rel="<?php _e("bookmark", "solostream"); ?>" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php include (TEMPLATEPATH . "/post-thumb.php"); ?></a>
   
       						<h3 class="post-title"><a href="<?php the_permalink() ?>" rel="<?php _e("bookmark", "solostream"); ?>" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php the_title(); ?></a></h3>
   
       						<?php the_excerpt(); ?>
   
       					</div>
   
       					<?php include (TEMPLATEPATH . "/postinfo.php"); ?>
   
       					<div style="clear:both;"></div>
   
       				</div>
       		<?php
       		}
   
       		echo "</div>\n";
   
       		echo $after_widget;
   
       		remove_filter('excerpt_length', $new_excerpt_length);
   
       		$post = $post_old; // Restore the post object.
       }
       ```
   
 * if you see, this row:
 *     ```
       // Get array of post info.
       		$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&post_type=any");
       ```
   
 * filters what posts/pages will be shown.
 * The problem is:
    when I show this widget, it will show me always the last X posts/
   pages of that category, it does not care about language.
 * What I can add in that WP_Query code to filter also by language?
 * Can you help me?
 * i try to write:
 *     ```
       // Get array of post info.
       		$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . "&post_type=any&lang=it");
       ```
   
 * but it doesn’t work. It always show me the last x post/pages in cronological 
   order.
 * Can you help me?
 * [http://wordpress.org/plugins/ceceppa-multilingua/](http://wordpress.org/plugins/ceceppa-multilingua/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Alessandro Senese aka Ceceppa](https://wordpress.org/support/users/ceceppa/)
 * (@ceceppa)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/widget-category-posts/#post-4462859)
 * Hi,
    try this:
 * // Get array of post info.
    global $wpCeceppaML; $cat_posts = new WP_Query(“showposts
   =” . $instance[“num”] . “&cat=” . $instance[“cat”] . “&post_type=any&post__in
   =” . $wpCeceppaML->$wpCeceppaML->get_posts_by_language( 1 ) );
 * In the example 1 is the id of “Italian” language.
 * You could also use the function “cml_get_posts_by_language”, but it has a bug,
   I’ll fix it in 1.3.46
 * Regards
 *  Thread Starter [femetal](https://wordpress.org/support/users/femetal/)
 * (@femetal)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/widget-category-posts/#post-4462892)
 * Hi Alessandro,
 * I try it, but it doesn’t work.
 * the output is a blank widget.
 * Do you have any other ideas?
 * How can I use “cml_get_posts_by_language”?
 * I’ have already 1.3.46 version.
 * Grazie
 * Ciao
 *  Plugin Author [Alessandro Senese aka Ceceppa](https://wordpress.org/support/users/ceceppa/)
 * (@ceceppa)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/widget-category-posts/#post-4462893)
 * Sorry, I wanted to say 1.3.47…
    Can you contact me here: [http://alessandrosenese.eu/contatti](http://alessandrosenese.eu/contatti)?
 * I’ll send you version 1.3.47…
 * The usage of cml_get_posts_by_language is:
 * //id of desired language…
    cml_get_posts_by_language( $id );

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Widget Category Posts’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ceceppa-multilingua_4faedb.svg)
 * [Ceceppa Multilingua](https://wordpress.org/plugins/ceceppa-multilingua/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ceceppa-multilingua/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ceceppa-multilingua/)
 * [Active Topics](https://wordpress.org/support/plugin/ceceppa-multilingua/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ceceppa-multilingua/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ceceppa-multilingua/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [ceceppa](https://wordpress.org/support/topic-tag/ceceppa/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 3 replies
 * 2 participants
 * Last reply from: [Alessandro Senese aka Ceceppa](https://wordpress.org/support/users/ceceppa/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/widget-category-posts/#post-4462893)
 * Status: not resolved