Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #439645

    Hello !

    I try to personnalize the widget latest-news ( I want to add a link, move title and image etc…)

    I add the code below to a function.php of my child theme ( i saw it here : )

    The new widget is correctly create but the change i made in function widget() doesn’t look to be applied

    There is a better way to do that ?

    Thx !

    
    add_action('after_setup_theme','avia_load_additional_widget');
    function avia_load_additional_widget()
    {
    	if (!class_exists('avia_customcptbox'))
    	{
    		class avia_customcptbox extends avia_newsbox
    		{
    			function avia_customcptbox()
    			{
    				$this->avia_term = '';
    				$this->avia_post_type = '';
    				$this->avia_new_query = ''; //set a custom query here
    				$widget_ops = array('classname' => 'newsbox', 'description' => 'Derniere actualite' );
    
    				$this->WP_Widget( 'customcptbox', THEMENAME.' actualite', $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 = "square";
    
    			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;
    
    		}
    
    		register_widget( 'avia_customcptbox' );
    	}
    }
    #440422

    Hey leplusweb!

    What change did you do that is not being applied?

    Best regards,
    Elliott

    #440455

    Hey,

    all change i’m doing at the code below function widget($args, $instance)

    For example I add a class test_class at the ul news-wrap. It’s not appear :
    echo '<ul class="news-wrap test_class image_size_'.$image_size.'">';

    I think my new widget is properly declare, but i can’t customize it. The methodology is not correct ? I can use the functions.php to customize a widget ?

    Thx !
    Best regards,

    #441076

    Hey!

    Not sure. Try copying the newsbox widget class to your child functions.php file and just change the naming around.

    I don’t think your add_action or function call is necessary.

    Regards,
    Elliott

    #458517

    Hey,

    thx for your help. You’re right, i copy / paste the class ‘avia_newsbox’ (without rename it) in the functions.php of my child_theme.

    After that I can personnalize the Front code of the widget.

    Regards,

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Personnalize Widget Latest news’ is closed to new replies.