Change fp-latest-news.php in child theme

Hello there,

I made a webpage with your Sydney and Sydney Child theme, and i want to change the picture’s size from 550x400px to 477x224px in the latest-news widget.

I modified the fp-latest-new.php file and it works in the parent’s theme, but if i upload into Child theme’s directory it doesnt work (“child theme\widgets\fp-latest-news.php”, but tried this way too: “child theme\fp-latest-news.php”).

And this is my question:
How can i apply this modified widget in the child’s theme?

Thank you very much!

Hello,

How can i apply this modified widget in the child’s theme?

I don’t think that there is an easy way to do that, unfortunately. However, you can check this topic, it might help:

Please feel free to ask any other questions that you might have.

Kind Regards, Roman.
aThemes Support

Hello,

Thank you for your fast reply.

If it possible i want to solve this problem without extra plugins, plus earlier i modified the functions.php file with this code what i find in your forums (which also doesn’t work in child’s functions.php):
add_theme_support( ‘title-tag’ );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
	 */
	add_theme_support( 'post-thumbnails' );
	add_image_size('sydney-large-thumb', 477);
	add_image_size('sydney-medium-thumb', 477, 224, true);
	add_image_size('sydney-small-thumb', 230);
	add_image_size('sydney-service-thumb', 350);
	add_image_size('sydney-mas-thumb', 480);

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'sydney' ),
	) );

If you say, there is no other way to override the original parent’s widget in child theme, i try your previous solution.

Thank you for your help.

Hello there,

Read this thread that will tell you how to override employee widget within a child theme; and do the same way for fp-latest-news.php file.

Regards,
Kharis

1 Like

Hello Kharis,

Thank you for your fast reply.

However i have a little problem. It seems like the code can’t register the new widget.

This is my new child functions.php file:
<?php
/* Sydney child functions
* Enqueues the parent stylesheet. Do not remove this function./
add_action( ‘wp_enqueue_scripts’, ‘sydney_child_enqueue’ );function sydney_child_enqueue() {wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );}
/
ADD YOUR CUSTOM FUNCTIONS BELOW */

/*
 * Requiring latest news widget file from childtheme
 */
require get_stylesheet_directory() . "/widgets/fp-latest-news.php";

/*
 * Unregistering default latest news widget
 */
function sydney_child_remove_latest_news_widget() {
	unregister_widget('Sydney_Latest_News');
}
add_action( 'widgets_init', 'sydney_child_remove_latest_news_widget', 999 );

/*
 * Registering new widget
 */
function sydney_child_register_new_widget(){
  register_widget( 'Sydney_Child_Latest_News' ); // Widget class name
}
add_action( 'widgets_init', 'sydney_child_register_new_widget' );

And this is my new fp-latest-news.php file (in “child theme\widgets\fp-latest-news.php”)
<?php

class Sydney_Child_Latest_News extends WP_Widget {

	public function __construct() {
		$widget_ops = array('classname' => 'sydney_latest_news_widget', 'description' => __( 'Show the latest news from your blog.', 'sydney') );
        parent::__construct(false, $name = __('Sydney FP: Latest News', 'sydney'), $widget_ops);
		$this->alt_option_name = 'sydney_latest_news_widget';
		
    }
	
	function form($instance) {
		$title     		= isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
		$category  		= isset( $instance['category'] ) ? esc_attr( $instance['category'] ) : '';
		$see_all_text  	= isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';											
	?>

	<p>
	<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'sydney'); ?></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>

	<p><label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Enter the slug for your category or leave empty to show posts from all categories.', 'sydney' ); ?></label>
	<input class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo $category; ?>" size="3" /></p>	

    <p><label for="<?php echo $this->get_field_id('see_all_text'); ?>"><?php _e('Add the text for the button here if you want to change the default <em>See all our news</em>', 'sydney'); ?></label>
	<input class="widefat custom_media_url" id="<?php echo $this->get_field_id( 'see_all_text' ); ?>" name="<?php echo $this->get_field_name( 'see_all_text' ); ?>" type="text" value="<?php echo $see_all_text; ?>" size="3" /></p>		

	<?php
	}

	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['title'] 			= strip_tags($new_instance['title']);
		$instance['category'] 		= strip_tags($new_instance['category']);
		$instance['see_all_text'] 	= strip_tags($new_instance['see_all_text']);						

		return $instance;
	}
		
	// display widget
	function widget($args, $instance) {
		if ( ! isset( $args['widget_id'] ) ) {
			$args['widget_id'] = $this->id;
		}
		extract($args);

		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '';
		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
		$category = isset( $instance['category'] ) ? esc_attr($instance['category']) : '';
		$see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : __( 'See all our news', 'sydney' );
		if ($see_all_text == '') {
			$see_all_text = __( 'See all our news', 'sydney' );
		}

		$r = new WP_Query( array(
			'no_found_rows'       => true,
			'post_status'         => 'publish',
			'posts_per_page'	  => 3,
			'category_name'		  => $category
		) );

		echo $args['before_widget'];

		if ($r->have_posts()) :
?>
		<?php if ( $title ) echo $before_title . $title . $after_title; ?>

		<?php while ( $r->have_posts() ) : $r->the_post(); ?>
			<div class="blog-post col-md-4 col-sm-6 col-xs-12">
			<?php if ( has_post_thumbnail() ) : ?>
				<div class="entry-thumb">
					<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
						<?php the_post_thumbnail('sydney-large-thumb'); ?>
					</a>			
				</div>	
			<?php endif; ?>						
			<?php the_title( sprintf( '<h4 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h4>' ); ?>
			</div>
		<?php endwhile; ?>

		<?php $cat = get_term_by('slug', $category, 'category') ?>
		<?php if ($category) : //Link to the category page instead of blog page if a category is selected ?>
			<a href="<?php echo esc_url(get_category_link(get_cat_ID($cat -> name))); ?>" class="roll-button more-button"><?php echo $see_all_text; ?></a>
		<?php elseif ( get_option( 'page_for_posts' ) ) : ?>
			<a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>" class="roll-button more-button"><?php echo $see_all_text; ?></a>
		<?php endif; ?>		
	<?php
		echo $args['after_widget'];
		wp_reset_postdata();

		endif;
	}
	
}

Can u see what is the problem? My latest news widget doesnt display.

Thank you very much!

Hello,

Problem solved. The widget is not visible in the “Sydney Theme Widgets”, but in the “All Widgets”.

Thank you for your help!

Have a nice day!

Great!

You’re welcome!

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

Regards,
Kharis