Tagged: Latest news widget
-
AuthorPosts
-
October 15, 2015 at 2:56 pm #519348
Hi,
how can i reverse the order of the posts from “Latest News Widget” from descending to ascending order?Thanks in advance,
SoltnerOctober 15, 2015 at 5:46 pm #519451Hi soltner!
Please go to /enfold/framework/php/class-framework-widgets.php and find following on line 451
$additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
and change it to
$additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count."&orderby=asc");
Regards,
YigitOctober 15, 2015 at 5:55 pm #519459Hi soltner!
Open up /enfold/framework/php/class-framework-widgets.php and change line 451 from this.
$additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
To this.
$additional_loop = new WP_Query("orderby=date&order=ASC&cat=".$cat."&posts_per_page=".$count);
Best regards,
ElliottOctober 16, 2015 at 9:45 am #519731Hi!
Thanks for the quick response. Works perfectly!
There is a way to make this change in the child-theme?Regards
SoltnerOctober 19, 2015 at 5:51 pm #521094Hi!
Yes, you can copy the whole class (lines 409 – 465) to the bottom of your child theme functions.php file and it will be used instead of the parent theme.
Best regards,
ElliottOctober 19, 2015 at 6:17 pm #521110Hi,
thanks for the reply!…tried it according to your instructions (https://dl.dropboxusercontent.com/u/4900424/screenshot.png), but the following error message appears:
Parse error: syntax error, unexpected end of file in /Applications/XAMPP/xamppfiles/htdocs/local/wp-content/themes/enfold-child/functions.php on line 100What did I do wrong?
Thanks,
SoltnerOctober 20, 2015 at 4:48 am #521338Hi,
You most likely have an error somewhere, could you post the code you are using please? Or we can have a look ourselves if you post login details in the Private Content area.
Regards,
RikardOctober 20, 2015 at 8:46 am #521439Hi,
i think so…Here’s the code:
/**
* AVIA NEWSBOX
*
* Widget that creates a list of latest news entries
*
* @package AviaFramework
* @todo replace the widget system with a dynamic one, based on config files for easier widget creation
*/if (!class_exists(‘avia_newsbox’))
{
class avia_newsbox extends WP_Widget {var $avia_term = ”;
var $avia_post_type = ”;
var $avia_new_query = ”;function __construct()
{
$widget_ops = array(‘classname’ => ‘newsbox’, ‘description’ => ‘A Sidebar widget to display latest post entries in your sidebar’ );parent::__construct( ‘newsbox’, THEMENAME.’ Latest News’, $widget_ops );
}function widget($args, $instance)
{
global $avia_config;extract($args, EXTR_SKIP);
echo $before_widget;$title = empty($instance[‘title’]) ? ” : apply_filters(‘widget_title’, $instance[‘title’]);
$count = empty($instance[‘count’]) ? ” : $instance[‘count’];
$cat = empty($instance[‘cat’]) ? ” : $instance[‘cat’];
$excerpt = empty($instance[‘excerpt’]) ? ” : $instance[‘excerpt’];
$image_size = isset($avia_config[‘widget_image_size’]) ? $avia_config[‘widget_image_size’] : ‘widget’;if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
if(empty($this->avia_term))
{
$additional_loop = new WP_Query(“cat=”.$cat.”&posts_per_page=”.$count);
}
else
{
$catarray = explode(‘,’, $cat);if(empty($catarray[0]))
{
$new_query = array(“posts_per_page”=>$count,”post_type”=>$this->avia_post_type);
}
else
{
if($this->avia_new_query)
{Thanks for your help!
SoltnerOctober 20, 2015 at 9:33 pm #522016Hi!
Sorry, I got the line numbers wrong for some reason. Here is the full class that you can copy to your child theme functions.php file.
/** * AVIA NEWSBOX * * Widget that creates a list of latest news entries * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ if (!class_exists('avia_newsbox')) { class avia_newsbox extends WP_Widget { var $avia_term = ''; var $avia_post_type = ''; var $avia_new_query = ''; function __construct() { $widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest post entries in your sidebar' ); parent::__construct( 'newsbox', THEMENAME.' Latest News', $widget_ops ); } function widget($args, $instance) { global $avia_config; extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $count = empty($instance['count']) ? '' : $instance['count']; $cat = empty($instance['cat']) ? '' : $instance['cat']; $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt']; $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget'; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; if(empty($this->avia_term)) { $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count); } else { $catarray = explode(',', $cat); if(empty($catarray[0])) { $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type); } else { if($this->avia_new_query) { $new_query = $this->avia_new_query; } else { $new_query = array( "posts_per_page"=>$count, 'tax_query' => array( array( 'taxonomy' => $this->avia_term, 'field' => 'id', 'terms' => explode(',', $cat), 'operator' => 'IN') ) ); } } $additional_loop = new WP_Query($new_query); } if($additional_loop->have_posts()) : echo '<ul class="news-wrap image_size_'.$image_size.'">'; while ($additional_loop->have_posts()) : $additional_loop->the_post(); $format = ""; if(empty($this->avia_post_type)) $format = $this->avia_post_type; if(empty($format)) $format = get_post_format(); if(empty($format)) $format = 'standard'; $the_id = get_the_ID(); $link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : get_permalink(); echo '<li class="news-content post-format-'.$format.'">'; //check for preview images: $image = ""; if(!current_theme_supports('force-post-thumbnails-in-widget')) { $slides = avia_post_meta(get_the_ID(), 'slideshow', true); if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) ) { $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image'); } } if(current_theme_supports( 'post-thumbnails' ) && !$image ) { $image = get_the_post_thumbnail( $the_id, $image_size ); } $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_newsbox' ); echo "<a class='news-link' title='".get_the_title()."' href='".$link."'>"; $nothumb = (!$image) ? 'no-news-thumb' : ''; echo "<span class='news-thumb $nothumb'>"; echo $image; echo "</span>"; if(empty($avia_config['widget_image_size']) || 'display title and excerpt' != $excerpt) { echo "<strong class='news-headline'>".get_the_title(); if($time_format) { echo "<span class='news-time'>".get_the_time($time_format)."</span>"; } echo "</strong>"; } echo "</a>"; if('display title and excerpt' == $excerpt) { echo "<div class='news-excerpt'>"; if(!empty($avia_config['widget_image_size'])) { echo "<a class='news-link-inner' title='".get_the_title()."' href='".$link."'>"; echo "<strong class='news-headline'>".get_the_title()."</strong>"; echo "</a>"; if($time_format) { echo "<span class='news-time'>".get_the_time($time_format)."</span>"; } } the_excerpt(); echo "</div>"; } echo '</li>'; endwhile; echo "</ul>"; wp_reset_postdata(); endif; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['count'] = strip_tags($new_instance['count']); $instance['excerpt'] = strip_tags($new_instance['excerpt']); $instance['cat'] = implode(',',$new_instance['cat']); return $instance; } function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) ); $title = strip_tags($instance['title']); $count = strip_tags($instance['count']); $excerpt = strip_tags($instance['excerpt']); $elementCat = array("name" => "Which categories should be used for the portfolio?", "desc" => "You can select multiple categories here", "id" => $this->get_field_name('cat')."[]", "type" => "select", "std" => strip_tags($instance['cat']), "class" => "", "multiple"=>6, "subtype" => "cat"); //check if a different taxonomy than the default is set if(!empty($this->avia_term)) { $elementCat['taxonomy'] = $this->avia_term; } $html = new avia_htmlhelper(); ?> <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p> <p> <label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display: </label> <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"> <?php $list = ""; for ($i = 1; $i <= 20; $i++ ) { $selected = ""; if($count == $i) $selected = 'selected="selected"'; $list .= "<option $selected value='$i'>$i</option>"; } $list .= "</select>"; echo $list; ?> </p> <p><label for="<?php echo $this->get_field_id('cat'); ?>">Choose the categories you want to display (multiple selection possible): <?php echo $html->select($elementCat); ?> </label></p> <p> <label for="<?php echo $this->get_field_id('excerpt'); ?>">Display title only or title & excerpt</label> <select class="widefat" id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>"> <?php $list = ""; $answers = array('show title only','display title and excerpt'); foreach ($answers as $answer) { $selected = ""; if($answer == $excerpt) $selected = 'selected="selected"'; $list .= "<option $selected value='$answer'>$answer</option>"; } $list .= "</select>"; echo $list; ?> </p> <?php } } }
Cheers!
ElliottOctober 21, 2015 at 5:37 pm #522395Hi Elliott,
now works perfectly ,-)Thanks a lot!
Regards,
Soltner -
AuthorPosts
- The topic ‘Latest News Widget – Reverse order’ is closed to new replies.