1

I switched to another theme and decided to make a widget of some default code I had in there which shows my delicious posts, twitter posts, su posts and youtube vids in a custom loop (excluding these categories from the main loop).

But now...the paging no longer works.

I have made this widget:

// =============================== EDL Sidebar Posts Widget ======================================
class SidebarPosts extends WP_Widget {

function SidebarPosts() {
    parent::WP_Widget(false, $name = 'Sidebar Posts'); 
}

/** @see WP_Widget::widget */
function widget($args, $instance) {  
    extract( $args );

    $title = apply_filters('widget_title', $instance['title']);
    echo $before_widget; if ( $title )
    echo $before_title . $title . $after_title; 
    $title = apply_filters('widget_title', $instance['title']);

    global $wp_query;

    $wp_query = new WP_Query();
    $wp_query->set('cat', '1172,14,867');
    $wp_query->set('posts_per_page', 30);
    $wp_query->set('offset', $paged*30);  
    $posts = $wp_query->get_posts(); 
    if ($posts) : 
        foreach ($posts as $post) : the_post();
            if (in_category(14)) { 
                echo $this->createSideBarLine($post, 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/delicious/f.png', false, true, true);  
            } elseif (in_category(1172)) { 
                echo $this->createSideBarLine($post, '/wp-content/themes/edl/inc/banners/twitter.gif', false, true, true); 
            } elseif (in_category(867)) { 
                echo $this->createSideBarLine($post, 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/stumbleupon/www/f.png', true, true, true);
            } 
        endforeach; 
        echo "<p>" . _e('More on the Next Page!') . "</p>";   
        wp_link_pages(array('next_or_number'=>'next', 'previouspagelink' => ' &laquo; ', 'nextpagelink'=>' &raquo;'));

    else: 
        echo "<p>" . _e('Jump to the frontpage for the list') . '</p>';
    endif; 

    echo $after_widget;
}

/** @see WP_Widget::update */
function update($new_instance, $old_instance) {    
    return $new_instance;
}

/** @see WP_Widget::form */
function form($instance) {  
$title = apply_filters('widget_title', $instance['title']);
    ?>
<p>
    <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> </label>
    <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<?php }

function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    return $content;
}

//
// Shows a line in the LifeFeed / IssueFeed / BrainFeed sidebar
// widgets
//
function createSideBarLine($post,$strImage, $boolShowTitle, $boolShowExcerpt, $boolShowContent) {
    global $wp_query;

    $strBuffer="";
    $strTitle = strip_tags(get_the_title());
    $strPermalink = get_permalink($post->ID);
    $intId = $post->ID;
    $strContent = $this->get_the_content_with_formatting();
    $strContent = str_replace('<p>', '', $strContent);
    $strEditPostLink = get_edit_post_link();

    // if content contains "YouTube" then use YouTube icon
    if (strstr($strContent, 'YouTube')) {
        $strImage = 'http://populair.eu/wp-content/themes/pop/bookmark_info/com/youtube/www/f.png';
    }

    $strBuffer.= '<div class="tb-link" id="post-'.  $intId . '">';
    $strBuffer.= '<p><a href="' . $strPermalink; 
    $strBuffer.= '" rel="nofollow bookmark" title="Permanent Link to ';
    $strBuffer.= $title . '">';
    $strBuffer.= '<img src="'. $strImage . '" align="left" ';
    $strBuffer.= 'width="12" style="border: 0px none;';
    $strBuffer.= 'margin: 0px 10px 0px 0px; display: inline;">';
    $strBuffer.= '</a>';
    if ($boolShowTitle) {
        $strBuffer.= '<a href="' . $strPermalink;
        $strBuffer.= '" rel="nofollow bookmark"'; 
        $strBuffer.= 'title="Permanent Link to ' . $strTitle . '">';
        $strBuffer.= $strTitle . "</a>";
    }
    if ($boolShowExcerpt) {
        $strBuffer.= $post->post_excerpt;
    }
    if ($boolShowContent) {
        $strBuffer.= $strContent;
    }  
    if (is_admin()) {
        $strBuffer.= '<a href="'. $strEditPostLink . '" class="editpost">';
        $strBuffer.= ' [edit]</a>';
    }  
    $strBuffer.= "</p></div>";   
    return $strBuffer;   
}
}

I think the in the previous theme it could pick up the $paged from the main loop or something now it no longer shows any paging so it always only shows the first 30 items.

(see http://edward.de.leau.net/ for the thing, busy converting to swift theme)

1

Try doing global $paged before using the variable in the widget function.

1
  • I just wanted to add that in order to have it working on the homepage you have to subtract 1 from $paged when in the home environment. (contrary to pages). I havent coded it yet for the archives.
    – edelwater
    Oct 15 '10 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.