Display recent exhibits on homepage

79 views
Skip to first unread message

Erin Bell

unread,
Jun 3, 2011, 10:52:02 AM6/3/11
to omek...@googlegroups.com
Hi,

I'd like to display one or more recent exhibits on my homepage.  I've adapted from the exhibit_builder_random_featured_exhibit() function to come up with the following, but it's throwing Zend errors when I try to get the links:


//Returns Recent Exhibit for display on homepage
function deco_exhibit_builder_display_recent_exhibit($num=1)
{
    if (function_exists('exhibit_builder_link_to_exhibit'))
{
    $html = '<div id="recent-exhibit">';
    $recentExhibit = get_db()->getTable('Exhibit')->findBy(array('recent'=>true), $num);
    $html .= '<h2>Recent Exhibits</h2>';
   
    if ($recentExhibit)
    {
       $html .= '<h3>' . exhibit_builder_link_to_exhibit($recentExhibit) . '</h3>';
       $html .= '<p>' . snippet($recentExhibit->description, 0, 500,exhibit_builder_link_to_exhibit($recentExhibit, '<br/>...more')) . '</p>';

    }
    else
    {
       $html .= '<p>You have no recent exhibits.</p>';
    }
    $html .= '</div>';
    return $html;
} }


This is the error message:

Warning: urlencode() expects parameter 1 to be string, array given in /home/content/30/4717730/html/omeka-dev/application/libraries/Zend/Controller/Router/Route.php on line 399

What am I doing wrong here?

Thanks -- Erin

John Flatness

unread,
Jun 3, 2011, 10:55:00 AM6/3/11
to omek...@googlegroups.com
The issue you're having is that the findBy method you use to get
$recentExhibit doesn't return an Exhibit, it returns an array of
Exhibits (even if you set the limit to 1).

You can either just pull out the first entry in the array
($recentExhibit[0]), or, since you've got a settable parameter for
number, you probably want to do a foreach loop over the exhibits you get
from findBy, running exhibit_builder_link_to_exhibit on each one.

-John

> --
> You received this message because you are subscribed to the Google
> Groups "Omeka Dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/omeka-dev/-/ZHh2d1VCMEdsaXdK.
> To post to this group, send email to omek...@googlegroups.com.
> To unsubscribe from this group, send email to
> omeka-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/omeka-dev?hl=en.

Erin Bell

unread,
Jun 3, 2011, 11:42:05 AM6/3/11
to omek...@googlegroups.com
Perfect. Thanks, John.

Here's what I'm using...

//Returns Recent Exhibit for display on homepage
function deco_exhibit_builder_display_recent_exhibit($num=3)

{
    if (function_exists('exhibit_builder_link_to_exhibit'))
{
    $html = '<div id="recent-exhibit">';
    $recentExhibit = get_db()->getTable('Exhibit')->findBy(array('recent'=>true), $num);
    $html .= '<h2>Recently Added</h2>';
   
    if ($recentExhibit)
    {
    foreach( $recentExhibit as $index => $exhibit){
       $html .= '<h3>' . exhibit_builder_link_to_exhibit($recentExhibit[$index]) . '<span class="exhibit-credit">&nbsp;by '. snippet($recentExhibit[$index]->credits,0,100).'</span></h3>';
       $html .= '<p>' . snippet($recentExhibit[$index]->description, 0, 500,exhibit_builder_link_to_exhibit($recentExhibit[$index], '<br/>...more')) . '</p>';

Christy Karpinski

unread,
Jul 17, 2016, 12:27:38 AM7/17/16
to Omeka Dev
Hi Erin, 

This post is from 5 years ago but hoping maybe you can help. 

This function you wrote, I am guessing I could put it in the custom.php file for the theme I am working on, but then how do I use it on the index.php page?

Thanks!
Christy

Erin Bell

unread,
Jul 18, 2016, 9:07:41 AM7/18/16
to Omeka Dev
Hi Christy,

That code is probably too old to work with any recent versions of Omeka. You might want to create a new function, getting exhibits with Omeka's get_records() function. So maybe something like...

$recentExhibits = get_records('Exhibit', array('recent'=>true), 3);

Then you would just loop through the results with something like...

if ($recentExhibits){
 
 
foreach( $recentExhibits as $exhibit){
 $html
.= '<div class="featured-exhibit">';
 $html
.= '<h2>Recent Exhibit</h2>';
 
 $html
.= '<h3>' . exhibit_builder_link_to_exhibit($exhibit) . '</h3>';
 
 $snippetlink
= '&nbsp;'.exhibit_builder_link_to_exhibit($exhibit,'... Continue Reading.').'';
 $html
.= '<p>' . snippet($exhibit->description, 0, 600,$snippetlink) . '</p>';
 
 $html
.= '</div>';
 
}
}


You can put that right in your index.php file or create a new function in custom.php.
Reply all
Reply to author
Forward
0 new messages