What Do You Need In The Xf2 Xengallery Version? Vote for your choices here: http://www.sonnb.com/threads/what-do-you-need-in-the-xf2-xengallery-version.1539/

Render Model

Discussion in 'XenGallery' started by dknife, Feb 14, 2015.

  1. dknife

    dknife YakTribe Gaming Authorized

    If you just use my code example, it will produce a blank page as there's no output. It's up to you to do something with data sets as that's completely up to each person on what they're trying to achieve.
     
  2. Dave

    Dave Authorized Member Authorized

    Yes, i gathered that. Thanks. Any examples of code would be appreciated. Even if it was just to show the possibilities.
    Thanks again.

    Upto now, i have got 5 images in a row using;
    Code:
    echo '<img src="forums/' . $photo['thumbnailUrl'] . '" title="Image by: ' . $photo['username'] . '" height="100" width="100"/>';
    Now to work on linking the thumbnail to the main image.
     
    Last edited: Mar 15, 2015
  3. dknife

    dknife YakTribe Gaming Authorized

    To link the photo, you look at the existing URL structure for a gallery photo

    Code:
    /gallery/photos/[photo_title].[photo_id]/
    So in my given code you can take the photo title, make it simple URL friendly structure

    Code:
    $photourl = preg_replace('/[^a-zA-Z0-9\-\s]+/','',strtolower($photo['title']));
    $photourl = str_replace(' ','-',$photourl );
    So for your img url it would be

    Code:
    echo '<a href="forums/gallery/photos/'.$photourl.$photo['photo_id'].'/" title="View photo '.photo['title'].'"><img src="forums/' . $photo['thumbnailUrl'] . '" title="Image by: ' . $photo['username'] . '" height="100" width="100"/></a>';
     
  4. Dave

    Dave Authorized Member Authorized

    That doesnt seem to work either. The url comes as forums/gallery/photos// with no picture id
    The code i have added is:
    Code:
    echo '<a href="forums/gallery/photos/'.$photourl.$photo['photo_id'].'/" title="View photo '.&photo['title'].'"><img src="forums/' . $photo['thumbnailUrl'] . '" title="Image by: ' . $photo['username'] . '" style="border: dotted 1px #000;" hspace="3" height="100" width="100"/></a>';
    The "$" was missing from your code before the photo[title] but still it doesnt link to the original picture.

    Lookin at the url of photos on my site, they look like:
    Code:
    mydomain/forums/gallery/photos/flycolour-on-me.14096/
     
    Last edited: Mar 16, 2015
  5. dknife

    dknife YakTribe Gaming Authorized

    Sorry it's $photo['content_id'] instead of $photo['photo_id']. I don't know why $photourl isn't working. You don't really need it anyway as it's just for the full vanity URL and can contain anything (or not even be there) as long as the content_data_id is present.

    edit: fixed content_id

    Code:
    foreach ($contents as $photo) {
        $photourl = preg_replace('/[^a-zA-Z0-9\-\s]+/','',strtolower($photo['title']));
        $photourl = str_replace(' ','-',$photourl);
        echo '<a href="forums/gallery/photos/'.$photourl.'.'.$photo['content_id'].'/" title="View photo '.$photo['title'].'"><img src="forums/' . $photo['thumbnailUrl'] . '" title="Image by: ' . $photo['username'] . '" style="border: dotted 1px #000;" hspace="3" height="100" width="100"/></a>';
    }
     
    Last edited: Mar 16, 2015
  6. Dave

    Dave Authorized Member Authorized

    Now the photo id number doesnt match the member whos photo it is. Most are not found at all.
    ie
    my-photoname.2473
    directs to
    my-photoname.1345
    Goes to a different users gallery entirely.
    Even sometimes a different picture name entirely.

    I'll just direct every image to the full gallery for now as i was before.
     
    Last edited: Mar 16, 2015
  7. dknife

    dknife YakTribe Gaming Authorized

    I'm sorry, trying to rush responses without checking the field data. It's content_id, not content_data_id. I've modified my post above.
     
  8. Dave

    Dave Authorized Member Authorized

    Thats the one. Thanks for your persistence.
    Another thing i have noticed is that sometimes five images show as expected, but sometimes with an F5 refresh, only 3 or sometimes 4 images show. Why could this be, as it may look rubbish on my page if the full amount are not shown every time.
     
  9. dknife

    dknife YakTribe Gaming Authorized

    With that particular code it is getting the latest 5 albums and displaying one image from each. Currently it is not checking whether a photo exists in the album or not.

    Change
    Code:
    $albums = $gallerymodel->getAlbums(array(), array('order' => 'random', 'limit' => 3, 'offset' => 0));
    to this
    Code:
    $albums = $gallerymodel->getAlbums(array('photo_count' => array('>=',1)), array('order' => 'random', 'limit' => 3, 'offset' => 0));
     
  10. Dave

    Dave Authorized Member Authorized

    Your a star. Thanks so much :D
     
  11. sonnb

    sonnb Administrator Staff Member

    You should use:
    PHP:
    XenForo_Link::buildPublicLink('gallery/photos'$photo);
    Rather than parsing the link manually.
     
  12. dknife

    dknife YakTribe Gaming Authorized

    Great, thanks. I'm yet to become familiar with all the functions I should be using that's built into XenForo already.
     
  13. Dave

    Dave Authorized Member Authorized

    How would that be included if the code i have at the moment is
    Code:
    echo '<a href="/forums/gallery/photos/'.$photourl.'.'.$photo['content_id'].'/" title="View photo '.$photo['title'].'"><img src="/forums/' . $photo['thumbnailUrl'] . '" title="Image by: ' . $photo['username'] . '" style="border: solid 1px #000;" hspace="3" vspace="3" height="65" width="65"/></a>';
    Thanks
     
  14. sonnb

    sonnb Administrator Staff Member

    Could be:
    PHP:
    echo '<a href="' XenForo_Link::buildPublicLink('gallery/photos'$photo) . '" title="View photo '.$photo['title'].'"><img src="/forums/' $photo['thumbnailUrl'] . '" title="Image by: ' $photo['username'] . '" style="border: solid 1px #000;" hspace="3" vspace="3" height="65" width="65"/></a>';
     

Share This Page