21
Zap_English
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

22
trabis
Re: Publisher Random Item Image
  • 2017/5/6 16:26

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


$mainImage = $itemsObj ->getMainImage();

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

Not tested, sent by phone.

23
Zap_English
Re: Publisher Random Item Image

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

24
Bleekk
Re: Publisher Random Item Image
  • 2017/5/6 17:02

  • Bleekk

  • Theme Designer

  • Posts: 941

  • Since: 2002/12/14


Which Code do you use now?

25
Zap_English
Re: Publisher Random Item Image

what Trabis posted

26
Bleekk
Re: Publisher Random Item Image
  • 2017/5/6 17:42

  • Bleekk

  • Theme Designer

  • Posts: 941

  • Since: 2002/12/14


which one? post it please

27
Zap_English
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.

28
Bleekk
Re: Publisher Random Item Image
  • 2017/5/6 18:31

  • Bleekk

  • Theme Designer

  • Posts: 941

  • Since: 2002/12/14


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}>"/>

29
Zap_English
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

<{$block.title}>

so that it would display the title of the item.

the next line is your block image, modified as



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

30
Bleekk
Re: Publisher Random Item Image
  • 2017/5/7 8:19

  • Bleekk

  • Theme Designer

  • Posts: 941

  • Since: 2002/12/14


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

Login

Who's Online

171 user(s) are online (99 user(s) are browsing Support Forums)


Members: 0


Guests: 171


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits