Tagged: Latest news widget
-
AuthorPosts
-
December 18, 2018 at 7:00 pm #1046980
Dear Support Team,
I would like the “Latest News Widget” to show the date of upcoming events. (https://imgur.com/a/Tha3bJC) By default it shows the date on which an event (blogpost) was created, but since that was irritating I have hidden it with some custom code. (https://imgur.com/a/3vCoClf)
.news-time { display: none!important; }
I have 2 ideas on how to go about this:
1. Use a Meta Tag from custom fields (https://imgur.com/a/xoWTRAX) and display that in the widget.
2. Just change the time at which the post was created to the event date.What do you think is the best solution (least coding) and how would you go about this?
Thank you so much and I wish you a nice christmas time!Best Regards,
JanP.S: I cant use the excerpt to display the time, because on the events page i need the automatic, normal excerpts.
December 18, 2018 at 7:15 pm #1046986Another option would be to use an Event Plugin … because Events are different data than Blog Posts … not sure if i would recommend that but you can take it into consideration.
=> https://de.wordpress.org/plugins/the-events-calendar/Your second solution won’t work (i think) … because the dates of those events can be in the future which would cause them to not show up till that date …
A custom field is a good idea in my opinion. But it would need some coding to show it in your widget.
December 18, 2018 at 7:19 pm #1046987Thank you for the quick answer cg! Since there is already a few posts i would like to find a different solution than an event plugin.
Do you have any idea on how the code for embedding the custom field could look like?Regards,
JanDecember 18, 2018 at 7:38 pm #1046996I can’t create the code at the moment because in a few minutes i have to leave the office to go christmas shopping with the family … :-)
But here are some notes to the process i would take for your first option (custom fields):
– create a customized Widget based on the Avia News Widget (class-framework-widgets.php, line 843 ff.)
– or override it by declaring the class “avia_newsbox” before Enfold does
– inside the Widget code call the data of the custom fields of each element and add it to the html output———-
How to create a WordPress Widget:
=> https://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/How to get custom field data:
=> https://codex.wordpress.org/Custom_Fields#Getting_Custom_FieldsDecember 19, 2018 at 5:02 pm #1047243Hi cg,
thank you very much for the guideline, your the men! Since I am personally not smart enough to code, I sadly cant follow all of the steps . After one eternity I found the code, but its verrrry long and i have now idea what to do and where.
Could someone from the enfold team maybe help out?
I really appreciate your help cg but i understand you have a familie and cant hold hand with me here ;)
This is the code i found: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’, ‘avia_framework’) ); 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 ““; $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 ““; } echo ““; if( ‘display title and excerpt’ == $excerpt ) { echo “<div class=’news-excerpt’>”; if(!empty($avia_config[‘widget_image_size’])) { echo ““; echo “<strong class=’news-headline’>”.get_the_title().”“; echo ““; if($time_format) { echo “<span class=’news-time’>”.get_the_time($time_format).”</span>”; } } the_excerpt(); echo “</div>”; } echo ‘‘; endwhile; echo ““; 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?”, ‘avia_framework’), “desc” => __(“You can select multiple categories here”, ‘avia_framework’), “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’); ?>”><?php _e(‘Title:’, ‘avia_framework’); ?> <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’); ?>”><?php _e(‘How many entries do you want to display: ‘, ‘avia_framework’); ?></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’); ?>”><?php _e(‘Choose the categories you want to display (multiple selection possible):’, ‘avia_framework’); ?> <?php echo $html->select($elementCat); ?> </label></p> <p> <label for=”<?php echo $this->get_field_id(‘excerpt’); ?>”><?php _e(‘Display title only or title & excerpt’, ‘avia_framework’); ?></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’ => __( ‘show title only’, ‘avia_framework’ ), ‘display title and excerpt’ => __(‘display title and excerpt’, ‘avia_framework’) ); foreach ( $answers as $key => $answer ) { $selected = “”; if( $key == $excerpt ) $selected = ‘selected=”selected”‘; $list .= “<option $selected value=’$key’>$answer</option>”; } $list .= “</select>”; echo $list; ?> </p> <?php } } }
- This reply was modified 5 years, 11 months ago by Nu-Vision.
December 21, 2018 at 9:08 pm #1048364Hi Nu-Vision,
we apologize for the late response, however the forum is flooding with threads.
Can you try to post the code in pastebin: https://pastebin.com/ then put the link here, so we can try to check on it further.Best regards,
NikkoDecember 21, 2018 at 11:05 pm #1048440Hi Nikko,
No problem, totally understand that! You can find the code here: https://pastebin.com/FKgGPtTK
I am guessing it is an easy fix if ones knows what he is doing, sadly i don´t! :@Would be a little christmas miracle if you could do this for me!
Thank you so much!
JanDecember 29, 2018 at 8:19 am #1049161Hi,
Display the event date as a Meta Tag using custom fields and then add it to widgets would be a good idea.
I’m unable to test the above code but you may already know that we can display a shortcode for any element in the widget area.
Please enable debug mode by adding the code provided in this link to your functions.php file which can be accessed from Appearance > Editor
This lets you view the shortcode for all the page elements. Just copy the element shortcode and paste it in the widget area.
Best regards,
VinayJanuary 3, 2019 at 5:56 pm #1049664Hi Vinay,
I did exactly what you told me, this is the code I get:
[av_sidebar widget_area='Sidebar Pages' av_uid='av-14hvt']
[av_button label='Next events' link='manually,https://frankfurt.agbc.org/events/' link_target='' size='large' position='center' label_display='' icon_select='yes' icon='ue80b' font='entypo-fontello' color='theme-color' custom_bg='#444444' custom_font='#ffffff' av_uid='av-jonbc5vm' admin_preview_bg='']The meta key is event_date. Could you tell me what to do with it exactly and where to place it?
Thank you so much and happy new year!
JanJanuary 9, 2019 at 9:13 am #1051646Hi Nu-Vision,
We apologize for the late response.
Can you try to paste this code in your child theme’s functions.php: https://pastebin.com/aPvtEhuD
This should replace the default date and time with your event_date custom field.
Let us know if you need further assistance.Best regards,
NikkoJanuary 9, 2019 at 10:03 am #1051679Hi Nikko,
pure awesomeness, you guys rock! Thank you so much!
You can close the topic, it worked perfectly.Regards,
JanJanuary 9, 2019 at 10:07 am #1051682Hi Jan,
Glad that we could help you and thanks for your kind words :)
Feel free to create a new thread if you need more assistance.
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘Latest News Widget + Meta Tag’ is closed to new replies.