Hi all,
Have spent some time and altered the extension to allow you to use multiple fields and multiple categories. This is how it works…
There is a function called set_relationships(). In there you can list a field_id and the gallery_id you want it to get the categories from. You can set up as many field-gallery relationships as you like. The extract below shows you how to make field 9 display categories from gallery 1, and field 10 display categories from gallery 2.
function set_relationships() {
$r = array();
/*
$r[field_id] = gallery_id;
*/
$r[9] = 1;
$r[10] = 2;
return $r;
}
Hope people find this useful.
Cheers, Af.
I just implemented Rob1’s extension, which went by without a hitch. However, now I’m running into an odd error. I’m not sure it’s related to the extension, so this might not be the best thread for this. If so, my apologies in advance.
Right now, I’ve got one Photo Gallery (titled “gallery”) that has two categories. Each category has a number of photos in them. My plan was to then assign a particular category to a particular blog entry, so that a couple of photos in from a category would appear in the entry, with a link to the complete category.
I then added the following chunk of code to my weblog entry template:
{if category_id != ""}
<ul class="gallery">
{exp:gallery:entries gallery="gallery" category="{category_id}" orderby="title" sort="asc" columns="1" rows="3" dynamic="off"}
{entries}
{row}
<li>
<a href="http://{image_url}">{thumb_url}</a>
</li>
{/row}
{/entries}
{/exp:gallery:entries}
</ul>
{/if}
The problem is that the above code is not pulling in the photos from the correct gallery category. Regardless of which blog entry I look at, the same photos from the same category appear on both. I’ve verified that the correct gallery category ID – which is being held by the {category_id} tag, is being passed into the “category” parameter, but it’s as if the {exp:gallery:entries} tag is ignoring that parameter.
Any ideas would be appreciated. Thanks much.
Hi,
I think I’m missing something fundamental here. I haven’t used extensions before and God knows there are very little info.
I’ve created two custom fields in my publishing form, number 11 and 12 (number verified by the URL) and set formatting to “none”.
I’ve installed AfroBoy’s version of the Gallery Cats extension since I need several galleries called, changed the parameters inside the extension to
$r[12] = 1; $r[11] = 2;
(I’ve verified the numbers of the galleries as well).
The custom field dropdowns show up in the publishing field but is populated by exactly nothing.
I’ve tried to use both the “Populate the menu manually” setting in the custom field admin, as well as “Populate the menu from another custom field” where I choose the same field as the pre-populator ( I obviously can’t choose a gallery).
The only difference in the publishing dropdown is that the manual setting results in one “row”, but the “another custom field” setting result in a tall blank dropdown.
What to do?
/ Ayza
P.S. I tried Robin’s original Gallery Cat extension too, with the same result (only one gallery /custom field then).
Honestly haven’t looked at the extension, so it’s hard to say what could be going on. You could try turning ‘show queries’ on- see what’s being generated to create the publish page. That might give a clue as to why it’s not populating.
And I think I might shift this down to the extensions forum- it’s definitely a better fit at this point!
If I get a chance, I’ll download things and take a look. From here- can’t see why it would work in one case and not another. Any other extensions installed? This thread is old- so I doubt these took advantage of some of the newer options for ‘playing nice’ with other extensions.
The extensions are pretty easy to pick up, and handy for this sort of thing. I just cobbled a quick one together- here. Basically, open it up- and because I was lazy and didn’t want to deal with settings- set a variable in the file
What would you need to do if you wanted to enable this so that you could assign different galleries to different custom fields?
Let’s see- attaching here so it’s handy…. It’s a really simple extension- the bulk is:
$alter_field = 32;
if ($field_id == $alter_field)
{
$field_id = 'field_id_'.$alter_field;
$results = $DB->query("SELECT cat_id, gallery_id, cat_name FROM exp_gallery_categories WHERE gallery_id=2 ORDER BY cat_name");
$r = $DSP->input_select_header($field_id, '', 1);
$selected = ($field_data == '') ? 'y' : '';
$r .= $DSP->input_select_option('', 'None', $selected);
foreach ($results->result as $row)
{
$selected = ($field_data == $row['cat_id']) ? 'y' : '';
$r .= $DSP->input_select_option($row['cat_id'], $row['cat_name'], $selected);
}
$r .= $DSP->input_select_footer();
}
else
{
$r = $DSP->input_text('field_id_'.$field_id, $field_data, '50', $field_maxl, 'input', '100%', $field_js, $convert_ascii);
}
return $r;
So say you have two fields (id 3 and 7 and want to pull from a different gallery from each. Could do something like
$alter_fields = array(3, 7);
if (in_array($field_id, $alter_fields)
{
$field_id = 'field_id_'.$field_id;
if ($field_id == 3)
{
$results = $DB->query("SELECT cat_id, gallery_id, cat_name FROM exp_gallery_categories WHERE gallery_id=2 ORDER BY cat_name");
}
elseif ($field_id == 7)
{
$results = $DB->query("SELECT cat_id, gallery_id, cat_name FROM exp_gallery_categories WHERE gallery_id=4 ORDER BY cat_name");
}
$r = $DSP->input_select_header($field_id, '', 1);
etc.....
Untested, but that would be one approach. It’s really just a matter of adding some conditionals. That help?
Thanks Robin I hadn’t thought of doing it that way. But I’m having a slight problem - I’m getting the same dropdown options for the different custom fields.
This is what I’ve got:
function dropdown_pop($field_id, $field_data, $field_maxl, $field_js, $convert_ascii)
{
global $DSP, $IN, $LANG, $DB;
$alter_fields = array(15, 28);
if (in_array($field_id, $alter_fields))
{
$field_id = 'field_id_'.$field_id;
if ($field_id = 15)
{
$results = $DB->query("SELECT cat_id, gallery_id, cat_name FROM exp_gallery_categories WHERE gallery_id=2 ORDER BY cat_name");
}
elseif ($field_id = 28)
{
$results = $DB->query("SELECT cat_id, gallery_id, cat_name FROM exp_gallery_categories WHERE gallery_id=3 ORDER BY cat_name");
}
$r = $DSP->input_select_header($field_id, '', 1);
$selected = ($field_data == '') ? 'y' : '';
$r .= $DSP->input_select_option('', 'None', $selected);
foreach ($results->result as $row)
{
$selected = ($field_data == $row['cat_id']) ? 'y' : '';
$r .= $DSP->input_select_option($row['cat_id'], $row['cat_name'], $selected);
}
$r .= $DSP->input_select_footer();
}
else
{
$r = $DSP->input_text('field_id_'.$field_id, $field_data, '50', $field_maxl, 'input', '100%', $field_js, $convert_ascii);
}
return $r;
}
I changed if ($field_id == 15) to if ($field_id = 15) from your original example as there were no options being returned.
Heh. Yep- you need the two == and change this bit:
//$field_id = 'field_id_'.$field_id;
if ($field_id = 15)
{
Or just take it out- makes no sense there and it’s screwing up the conditionals. Then- unless I’m missing it- only place you’ll need to tweak will be
$r = $DSP->input_select_header($field_id, '', 1);
change to
$r = $DSP->input_select_header('field_id_'.$field_id, '', 1);
Make sense? Let’s see what that gives us.
Wow! This all seems really complicated and beyond my abilities.
Is there anything in the works for just assigning category groups from the weblogs to the galleries? I have 50 categories in my weblogs, and don’t want to have to go in and re-create them anew for the galleries. And then have to go through some complex extension thing to link them.
It seems logical. Then you just do related entries as if this were another weblog category.
OK, I will try to look at the extension concept on a more energetic day.
Thanks!
Rez
Hi Guys, This thread has been really helpful for me in getting my site on the right road. However I’m coming up against a barrier that I’m not sure how to get around.
To give context I’m developing a site where there are two blogs and a gallery interlinking and relating.
I’d like to have a page that shows a large image from a gallery with the options to scroll through the rest of the images in the gallery as well as having contents from a blog entry.
I thought best to do this with the url string:
http://mysite.com/our-work-client/{url_title}/C21/
This connects the blog entry I require and the gallery category but doesn’t show the next and previous links to the rest of the images in the gallery.
This is my code:
{exp:weblog:entries weblog="client" dynamic="off" limit="1" url_title="{segment_3}"}
<h1 class="clienttitle">{title}</h1>
{/exp:weblog:entries}
{exp:gallery:entries gallery="{gallery_name}" category="{segment_4}"}
<div class="clientLimg">{image_url}</div><div class="nextprev">
{/exp:gallery:entries}
{exp:gallery:next_entry gallery="{gallery_name}"}<a href="http://{path=marketing/our-work-client/{segment_3}/{segment_4}/}" class="rightlink">next →</a>{/exp:gallery:next_entry}
{exp:gallery:prev_entry gallery="{gallery_name}"}<a href="http://{path=marketing/our-work-client/{segment_3}/{segment_4}/}" class="leftlink">← previous</a>{/exp:gallery:prev_entry}</div>
I’d really appreciate some help! Feel like I”m running around in circles. THanks Patricia
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.