Пагинация в мини-цикле для сайдбара
1 окт. 2010 г., 22:04:55
Просмотры: 948
Голосов: 1
Я перешел на другую тему и решил сделать виджет из кода, который у меня был по умолчанию. Он показывает мои посты из Delicious, Twitter, StumbleUpon и YouTube в пользовательском цикле (исключая эти категории из основного цикла).
Но теперь... пагинация перестала работать.
Я создал этот виджет:
// =============================== Виджет постов для сайдбара EDL ======================================
class SidebarPosts extends WP_Widget {
function SidebarPosts() {
parent::WP_Widget(false, $name = 'Посты в сайдбаре');
}
/** @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('Ещё на следующей странице!') . "</p>";
wp_link_pages(array('next_or_number'=>'next', 'previouspagelink' => ' « ', 'nextpagelink'=>' »'));
else:
echo "<p>" . _e('Перейдите на главную страницу для просмотра списка') . '</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('Заголовок:'); ?> </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 = '(далее...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
//
// Показывает строку в виджетах LifeFeed / IssueFeed / BrainFeed
// для сайдбара
//
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();
// если содержимое содержит "YouTube", используем иконку YouTube
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="Постоянная ссылка на ';
$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="Постоянная ссылка на ' . $strTitle . '">';
$strBuffer.= $strTitle . "</a>";
}
if ($boolShowExcerpt) {
$strBuffer.= $post->post_excerpt;
}
if ($boolShowContent) {
$strBuffer.= $strContent;
}
if (is_admin()) {
$strBuffer.= '<a href="'. $strEditPostLink . '" class="editpost">';
$strBuffer.= ' [править]</a>';
}
$strBuffer.= "</p></div>";
return $strBuffer;
}
}
Я думаю, что в предыдущей теме он мог получать $paged из основного цикла или что-то в этом роде. Теперь он не показывает никакой пагинации, поэтому всегда отображаются только первые 30 элементов.
(см. http://edward.de.leau.net/ для примера, в процессе перехода на тему Swift)
Все ответы на вопрос
1
Похожие вопросы
2
ответов
1
ответов
3
ответов