xoops forums

Zap_English

Quite a regular
Posted on: 5/6 13:39
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#21

Re: Publisher Random Item Image

I'm not a programmer but couldn't there just be an IF/ELSE in the tpl file to show the image?

you can see what's happening with it at franksrecipes.net

trabis

Core Developer
Posted on: 5/6 16:26
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#22

Re: Publisher Random Item Image

$mainImage = $itemsObj ->getMainImage();

in #2 use this
$mainImage $itemsObj -
>
getMainImage(); 
if(!
$mainImage['image_path'] ){
$mainImage['image_path']='urltoyourdefaultimage';
}

Not tested, sent by phone.

Zap_English

Quite a regular
Posted on: 5/6 16:42
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#23

Re: Publisher Random Item Image

Error : ParseError: syntax error, unexpected 'else' (T_ELSE), expecting end of file

Bleekk

Theme Designer
Posted on: 5/6 17:02
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 902
Since: 2002/12/14
#24

Re: Publisher Random Item Image

Which Code do you use now?

Zap_English

Quite a regular
Posted on: 5/6 17:41
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#25

Re: Publisher Random Item Image

what Trabis posted

Bleekk

Theme Designer
Posted on: 5/6 17:42
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 902
Since: 2002/12/14
#26

Re: Publisher Random Item Image

which one? post it please

Zap_English

Quite a regular
Posted on: 5/6 17:52
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#27

Re: Publisher Random Item Image

Quote:

trabis wrote:
$mainImage = $itemsObj ->getMainImage();

in #2 use this
$mainImage $itemsObj -
>
getMainImage(); 
if(!
$mainImage['image_path'] ){
$mainImage['image_path']='urltoyourdefaultimage';
}

Not tested, sent by phone.

Bleekk

Theme Designer
Posted on: 5/6 18:31
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 902
Since: 2002/12/14
#28

Re: Publisher Random Item Image

items_random_item.php
change the publisher_items_random_item_show function
function publisher_items_random_item_show($options)
{
    
$block     = array();
    
$publisher PublisherPublisher::getInstance();
    
// creating the ITEM object
    
$itemsObj $publisher->getHandler('item')->getRandomItem('', array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED));

    if (!
is_object($itemsObj)) {
        return 
$block;
    }

    
$block['content']       = $itemsObj->getBlockSummary(300true); //show complete summary  but truncate to 300 if only body available
    
$block['id']            = $itemsObj->itemid();
    
$block['url']           = $itemsObj->getItemUrl();
    
$image                  $itemsObj->getMainImage();
    
$block['image']     = $image['image_path'];
    
    if(!
$block['image']){
        
$block['image'] = "path_to_your_default_image";
    } 
    
    
$block['lang_fullitem'] = _MB_PUBLISHER_FULLITEM;

    return 
$block;
}


in template add this
<img src="<{$block.image}>"/>

Zap_English

Quite a regular
Posted on: 5/7 7:59
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#29

Re: Publisher Random Item Image

OK, that worked, HOORAY!

But it caused another problem. Not sure why

The first line of the tpl file I had inserted <center><h4><{$block.title}></h4></center> so that it would display the title of the item.

the next line is your block image, modified as

<img src="<{$block.item_image}>" alt="" width="100" height="100" align="left" style="padding:5px;"/>

So now it displays the image correctly, and the beginning text of the article, but it stopped showing the Title. Now sure why that's happening

Bleekk

Theme Designer
Posted on: 5/7 8:19
Bleekk
Bleekk (Show more)
Theme Designer
Posts: 902
Since: 2002/12/14
#30

Re: Publisher Random Item Image

Add this line to the Block function
$block['title']            = $itemsObj->title();