Gallery Custom Condition Extenstion to link weblog and gallery
Posted: 09 February 2007 01:03 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

Before I submit this extension I wanted to check that I am not adding something that could have done much easier some other way and save myself a bit of embaressment.

I wanted to link a weblog entry to gallery entries so that I could display these images next to the weblog entry.  I was already using categories for something else, so the way I have done this is to link using the url_title.  I created a custom field in the gallery where I can put a list of url_titles, then use this extension to add a condition to the gallery select:

{exp:gallery:entries gallery=“seeds” condition=“custom_field_one=’{url_title}’” ...}

or to allow gallery entries to related to multiple weblog entries

{exp:gallery:entries gallery=“seeds” condition=“INSTR( custom_field_one,’{url_title}’ ) > 0”  ...}


If this sounds like a useful extension, I’ll post it up.

Phoebe

Profile
 
 
Posted: 09 February 2007 06:02 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32861
Joined  05-14-2004

What I’ve seen people do with this is simply to use a custom field in the weblog, then nest the gallery entries tag inside the weblog entries tag, calling the custom field as a parameter.  I haven’t done this myself and am not sure how well it works, but it’s another option.

 Signature 
Profile
MSG
 
 
Posted: 10 February 2007 02:43 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  845
Joined  08-05-2005

I have an immediate need for this functionality and am planning on trying Lisa’s method this week.  I’ll come back and report how it went.

Profile
 
 
Posted: 16 February 2007 03:23 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  845
Joined  08-05-2005

Hey there - some comments
here about doing it how Lisa described.

Your description of what the extension would do is a little confusing to me, it looks like it might do more than what I was trying to do but I’m not entirely sure.

Profile
 
 
Posted: 16 February 2007 03:50 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

What I wanted to do was keep all the images in the gallery and display them in the weblog entries using the url_title as the glue. The url_title from the weblog entry is entered in the custom_field_one for the gallery entry.  I wanted to be able to have zero, one or more images per weblog entry and also allow an image to appear in more than one weblog entry.

So it would work like this if there were two images for one weblog entry id:

Weblog entry id:234
title: Broad Bean Aquedulce
url_title: aquedulce

Gallery entry:123
title: Aquedulce Beans in Pod
custom_field_one: broad_bean, aquedulce


Gallery entry:126
title: Aquedulce Beans Seedlings
custom_field_one: broad_bean, aquedulce


In the template I have:

{exp:gallery:entries gallery="seeds" condition="INSTR(custom_field_one,'{url_title}')>0"  orderby="entry_date" columns="4" }
     
           
<table >
          
           
{entries}
           
           {row_start}
<tr>{/row_start}
           
           {row}
           
<td>
           <
a href="#"><img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}" title="{title}" /></a><br />
           
{title}
           
</td>
           
{/row}
           
           {row_blank}
<td>&nbsp;</td>{/row_blank}
           
           {row_end}
</tr>{/row_end}
           
           {
/entries}
           
           
</table>
     
     
{/exp:gallery:entries}

Does that help?

Profile
 
 
Posted: 20 February 2007 09:18 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  845
Joined  08-05-2005

Ah, I get it now. That’s interesting - and pretty different from what I was looking to do.  I’d say go for it.

Profile
 
 
Posted: 26 March 2007 01:47 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

This is the extension:

<?php

if ( ! defined('EXT'))
{
    
exit('Invalid file request');
}




class gallery_custom_condition
{
    
var $settings        = array();
    
    var
$name            = 'Gallery Custom Condition';
    var
$version        = '1.0.0';
    var
$description    = 'Allow additional conditions to be added to select statement for gallery:entries tag';
    var
$settings_exist    = 'n';
    var
$docs_url        = '';
    
    
// -------------------------------
    //   Constructor - Extensions use this for settings
    // -------------------------------
    
    
function gallery_custom_condition($settings='')
    
{
        $this
->settings = $settings;
    
}
    
// END


    
function add_to_sql($sql) {
    
              
global $TMPL,$DB;
         
       if (
$TMPL->fetch_param('condition')>' ')
               
               
$sql.='AND  '.$TMPL->fetch_param('condition').' ';



      return
$sql;
      
    
} //add_to_sql
    
    // --------------------------------
    //  Activate Extension
    // --------------------------------
    
    
function activate_extension()
    
{
        
global $DB;
        
        
$DB->query($DB->insert_string('exp_extensions',
                                      array(
'extension_id'    => '',
                                            
'class'            => "gallery_custom_condition",
                                            
'method'        => "add_to_sql",
                                            
'hook'            => "gallery_build_sql_query_add",
                                            
'settings'        => "",
                                            
'priority'        => 10,
                                            
'version'        => $this->version,
                                            
'enabled'        => "y"
                                            
)
                                     )
                   );



    
}
    
// END
    
    
    // --------------------------------
    //  Update Extension
    // --------------------------------  
    
    
function update_extension($current='')
    
{
        
if ($current == '' OR $current == $this->version)
        
{
            
return FALSE;
        
}
        
        
if ($current > '1.0.0')
        
{
            
// Update to next version 1.0.1
        
}
        
        $DB
->query("UPDATE exp_extensions
                    SET version = '"
.$DB->escape_str($this->version)."'
                    WHERE class = 'gallery_custom_condition'"
);
    
}
    
// END


}
// END Class

?>

Profile
 
 
Posted: 29 March 2007 04:14 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  60
Joined  08-10-2006

I have a need for something like this. But I’m such a code noob I’m not sure how to do it. I have a gallery with 10 or so categories. I want to specify certain images to be “featured” so I can showcase them on a page. In the gallery entry I have a dropdown for yes/no on the featured custom field. I created a custom field for this purpose. How would I use this extension to show just those featured images? What code would I use? I currently have:

{exp:gallery:entries gallery="portfolio2" orderby="random" limit="1" category="7|8|9|10"}
        
<img src="{image_url}" width="505" height="310" />
{/exp:gallery:entries}


Would I add something like condition=“custom_field_two=yes” ?

 Signature 

David Guy

Profile
 
 
Posted: 30 March 2007 03:54 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  332
Joined  10-11-2004

That should work yes.

Let me know if not.

Actual line in template I used:

{exp:gallery:entries gallery="seeds" condition="INSTR(custom_field_one,'{url_title}')>0"  orderby="entry_date" columns="4" }

Profile
 
 
Posted: 30 March 2007 10:00 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  60
Joined  08-10-2006

OK for some reason it’s ignoring the conditional and showing all photos. Any ideas?

{exp:gallery:entries gallery="portfolio2" condition="custom_field_two=yes" orderby="random" limit="1" category="8"}
     
<img src="{image_url}" />
{/exp:gallery:entries}

 Signature 

David Guy

Profile
 
 
Posted: 31 March 2007 11:46 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  217
Joined  11-12-2002

I use Mark Huots Multi Relationship extension for this.

You just get a list of gallery entries in the Publish page of your Control Panel and then select as many images as you want from a multi-select field. These can then be displayed within your weblog entry. Of course you can only see the title of the image.

Maybe you are wanting more than this?

 Signature 

PageToScreen

Profile
 
 
Posted: 02 April 2007 01:19 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  60
Joined  08-10-2006

Thanks, Chris, I’ll play with your idea.

I just need to know the correct syntax to use for showing an image based on the contents of a custom field. I suppose if I can’t figure out a way to do this I can just create a separate category just for these featured images.

edit: I could not find any instructions on how to use that extension so I’m back to using the one referenced in the topic.

 Signature 

David Guy

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64944 Total Logged-in Users: 72
Total Topics: 81925 Total Anonymous Users: 49
Total Replies: 440355 Total Guests: 299
Total Posts: 522280    
Members ( View Memberlist )