web-dev-qa-db-ja.com

サイドバーのミニループでのページング

私は別のテーマに切り替えて、私のおいしい投稿、Twitterの投稿、suの投稿、youtubeのvidを表示するデフォルトコードのウィジェットをカスタムループで作成することにしました(メインループからこれらのカテゴリを除く)。

しかし今、...ページングは​​機能しなくなりました。

私はこのウィジェットを作りました:

// =============================== 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;   
}
}

前のテーマではメインループから$ pagedを拾うことができたか、今はページングが表示されなくなったため、常に最初の30項目のみが表示されます。

(詳しくは http://edward.de.leau.net/ 、Swiftテーマに変換するのに忙しいです)

1
edelwater

ウィジェット関数で変数を使用する前にglobal $pagedを試してください。

1
sorich87