Paginazione in un mini loop nella sidebar
1 ott 2010, 22:04:55
Visualizzazioni: 948
Voti: 1
Ho cambiato tema e ho deciso di creare un widget con del codice predefinito che mostrava i miei post su Delicious, Twitter, SU e video di YouTube in un loop personalizzato (escludendo queste categorie dal loop principale).
Ma ora... la paginazione non funziona più.
Ho creato questo widget:
// =============================== Widget Post Sidebar EDL ======================================
class SidebarPosts extends WP_Widget {
function SidebarPosts() {
parent::WP_Widget(false, $name = 'Post Sidebar');
}
/** @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('Altro nella pagina successiva!') . "</p>";
wp_link_pages(array('next_or_number'=>'next', 'previouspagelink' => ' « ', 'nextpagelink'=>' »'));
else:
echo "<p>" . _e('Vai alla homepage per la lista completa') . '</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('Titolo:'); ?> </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 = '(altro...)', $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;
}
//
// Mostra una riga nei widget della sidebar 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();
// se il contenuto contiene "YouTube" usa l'icona di 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="Link permanente a ';
$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="Link permanente a ' . $strTitle . '">';
$strBuffer.= $strTitle . "</a>";
}
if ($boolShowExcerpt) {
$strBuffer.= $post->post_excerpt;
}
if ($boolShowContent) {
$strBuffer.= $strContent;
}
if (is_admin()) {
$strBuffer.= '<a href="'. $strEditPostLink . '" class="editpost">';
$strBuffer.= ' [modifica]</a>';
}
$strBuffer.= "</p></div>";
return $strBuffer;
}
}
Penso che nel tema precedente potesse prendere la variabile $paged dal loop principale o qualcosa del genere, ora non mostra più alcuna paginazione e mostra sempre solo i primi 30 elementi.
(vedi http://edward.de.leau.net/ per il sito, sto convertendo al tema Swift)
Tutte le risposte alla domanda
1
Domande correlate
2
risposte
1
risposte
3
risposte