Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not familiar with WPML plugin but if you have language specific categories, you can simply do that:</p> <pre><code>... &lt;ul class="recent-english-posts"&gt; &lt;?php $loop = new WP_Query('cat=' . get_category_by_slug('english')-&gt;term_id . '&amp;showposts=3'); if($loop-&gt;have_posts()): while($loop-&gt;have_posts()): $loop-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; else: ?&gt; No English posts yet! &lt;?php endif; ?&gt; &lt;/ul&gt; ... &lt;ul class="recent-spanish-posts"&gt; &lt;?php $loop-&gt;query('cat=' . get_category_by_slug('spanish')-&gt;term_id . '&amp;showposts=3'); if($loop-&gt;have_posts()): while($loop-&gt;have_posts()): $loop-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; else: ?&gt; No Spanish posts yet! &lt;?php endif; ?&gt; &lt;/ul&gt; ... &lt;ul class="recent-espanol-posts"&gt; &lt;?php $loop-&gt;query('cat=' . get_category_by_slug('espanol')-&gt;term_id . '&amp;showposts=3'); if($loop-&gt;have_posts()): while($loop-&gt;have_posts()): $loop-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; else: ?&gt; No Espanol posts yet! &lt;?php endif; ?&gt; &lt;/ul&gt; ... </code></pre> <p>By placing this code in your theme <code>sidebar.php</code> you'll hopefully done. But what if you want this as a widget? there are two solutions on my mind: </p> <p>First Solution: As you previously mentioned in your question update, you can fork the core! &amp; change the standard WordPress recent posts widget. Here you go by replacing the original <code>widget()</code> method of the <code>WP_Widget_Recent_Posts</code> class:</p> <pre><code>... function widget($args, $instance) { $cache = wp_cache_get('widget_recent_posts', 'widget'); /* pre-saving language-specific ids for ease of use &amp; code readability ofcourse! */ $cat_ids = array( 'en'=&gt;get_category_by_slug('english')-&gt;term_id, 'sp'=&gt;get_category_by_slug('spanish')-&gt;term_id, 'es'=&gt;get_category_by_slug('espanol')-&gt;term_id ); if ( !is_array($cache) ) $cache = array(); if ( isset($cache[$args['widget_id']]) ) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title']); if ( !$number = (int) $instance['number'] ) $number = 10; else if ( $number &lt; 1 ) $number = 1; else if ( $number &gt; 15 ) $number = 15; /* recent english posts loop */ $r = new WP_Query(array('cat' =&gt; $cat_ids['en'], 'showposts' =&gt; $number, 'nopaging' =&gt; 0, 'post_status' =&gt; 'publish', 'caller_get_posts' =&gt; 1)); if ($r-&gt;have_posts()) : ?&gt; &lt;?php echo $before_widget; ?&gt; &lt;?php if ( $title ) echo $before_title . $title . $after_title; ?&gt; &lt;ul&gt; &lt;?php while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?&gt;"&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt; &lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; /* recent spanish posts loop */ $r-&gt;query(array('cat' =&gt; $cat_ids['sp'], 'showposts' =&gt; $number, 'nopaging' =&gt; 0, 'post_status' =&gt; 'publish', 'caller_get_posts' =&gt; 1)); if ($r-&gt;have_posts()) : ?&gt; &lt;?php echo $before_widget; ?&gt; &lt;?php if ( $title ) echo $before_title . $title . $after_title; ?&gt; &lt;ul&gt; &lt;?php while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?&gt;"&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt; &lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; /* recent espanol posts loop */ $r-&gt;query(array('cat' =&gt; $cat_ids['es'], 'showposts' =&gt; $number, 'nopaging' =&gt; 0, 'post_status' =&gt; 'publish', 'caller_get_posts' =&gt; 1)); if ($r-&gt;have_posts()) : ?&gt; &lt;?php echo $before_widget; ?&gt; &lt;?php if ( $title ) echo $before_title . $title . $after_title; ?&gt; &lt;ul&gt; &lt;?php while ($r-&gt;have_posts()) : $r-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?&gt;"&gt;&lt;?php if ( get_the_title() ) the_title(); else the_ID(); ?&gt; &lt;/a&gt;&lt;/li&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt; &lt;?php echo $after_widget; ?&gt; &lt;?php wp_reset_query(); // Restore global post data stomped by the_post(). endif; $cache[$args['widget_id']] = ob_get_flush(); wp_cache_add('widget_recent_posts', $cache, 'widget'); } ... </code></pre> <p>But I do not prefer to use such a solution, changing the core is not a good idea! Also this could be a bad practice due to portability reasons while you can rewrite WordPress widgets! </p> <p>The second, yet preferable solution! In your theme's <code>functions.php</code> place the code below: </p> <pre><code>&lt;?php function widget_mytheme_recent_posts(){ ?&gt; &lt;!-- your new widget code will go there replace this comment by the first block of code in this answer, take care of php code blocks! --&gt; &lt;?php } //end of widget_mytheme_recent_posts() if(function_exists('register_sidebar_widget')) register_sidebar_widget(__('Recent Posts'), 'widget_mytheme_recent_posts'); /* the rest of functions.php code will go here, maybe sidebar registering! */ ?&gt; </code></pre> <p>Hope it help ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload