• Hi i need some help altering this code so that a category (ID: 9) is not shown in the recent posts list.
    ———————————————————
    function widget_recent_entries($args) {
    extract($args);
    $title = __(‘Nieuws’, ‘widgets’);
    $r = new WP_Query(‘showposts=10’);
    if ($r->have_posts()) :
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title . $title . $after_title; ?><div style=”background-image: url(https://www.toytastic.nl/wp-content/themes/toytastic/img/devider_line.gif); background-repeat: repeat-x; width: 175px; height: 2px;” align=”center”></div>

    <?php echo $after_widget; ?>
    <?php
    endif;
    }
    ———————————————————
    Thank you ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter lsshock

    (@lsshock)

    bumped :$

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Change:
    $r = new WP_Query('showposts=10');

    to:
    $r = new WP_Query('showposts=10&cat=-9');

    I think that will do the trick.

    This also works with WP 2.2 widget.php

    function wp_widget_recent_entries($args) {
    	if ( $output = wp_cache_get('widget_recent_entries') )
    		return print($output);
    
    	ob_start();
    	extract($args);
    	$options = get_option('widget_recent_entries');
    	$title = empty($options['title']) ? __('Recent Posts') : $options['title'];
    	if ( !$number = (int) $options['number'] )
    		$number = 10;
    	else if ( $number < 1 )
    		$number = 1;
    	else if ( $number > 15 )
    		$number = 15;
    
    	$r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0&cat=-7");

    Simply add the &cat=-7 at the end of the last line show in the example above to keep Category 7 posts from showing up in the Recent Posts widget.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help with recent posts widget’ is closed to new replies.