Hi, is there a way to assign a default image to NSP (on Joomla 5.2) in case the article's image is missing?
Thanks in advance, Franco

Hi Franco,

Suppose that you're using standard mode of this module and load the Joomla! articles content.

You can edit this file: root/modules/mod_news_pro_gk5/tmpl/com_content/view.php

Look for this function:

// original image
static function originalImage($config, $item) {
	$images = json_decode($item['images']);
	$IMG_SOURCE = '';

	if($config['thumb_image_type'] == 'full' && (isset($images) && $images->image_fulltext!= '')) {
		$IMG_SOURCE = $images->image_fulltext;
	} elseif($config['thumb_image_type'] == 'intro' && (isset($images) && $images->image_intro!='')) {
		$IMG_SOURCE = $images->image_intro;
	} else {
		// set image to first in article content
		$IMG_SOURCE = NSP_GK5_com_content_View::getImageFromText($item['text']);
	}

	return $IMG_SOURCE;
}

change to:

// original image
static function originalImage($config, $item) {
    $images = json_decode($item['images']);
    $IMG_SOURCE = '';
    $default_image = 'path/to/your/default_image.jpg'; // Set your default image path here
    
    if($config['thumb_image_type'] == 'full' && (isset($images) && $images->image_fulltext != '')) {
        $IMG_SOURCE = $images->image_fulltext;
    } elseif($config['thumb_image_type'] == 'intro' && (isset($images) && $images->image_intro != '')) {
        $IMG_SOURCE = $images->image_intro;
    } else {
        // set image to first in article content
        $IMG_SOURCE = NSP_GK5_com_content_View::getImageFromText($item['text']);
    }
    
    // Return the default image if no image is found
    if (empty($IMG_SOURCE)) {
        $IMG_SOURCE = $default_image;
    }
    
    return $IMG_SOURCE;
}

Thanks sagauros
I will set up a override.
I hope you will agree this function is useful and allow the user to input the image link in the configuration file.

Rgds, Franco

I will inform the team about this update. In the meantime, please proceed with this solution

Write a Reply...
You need to Login to view replies.