Lis pages by multiple attribute category

Permalink 1 user found helpful
Hi, I am making a film makers biography site and I need to be able to display links to the biography pages from other pages in the site based on category. For example one biography might come under the category of a certain type of equipment, a certain type of person, the country that they were from and the group of people they belonged to (e.g. performers).

I found this really helpful post
and got the Related Content block that Jordan has posted working fine, but I was wondering if it would be possible to use this but with different groups of categories - e.g Machines, Groups, Countries? At present when you make a page you have to scroll through a hug list to select the categories and it would be easier if that list could be broken up in to relvant sections.

Hope that makes sense! Its be puzzling me for days now!

Many thanks in advance.

View Replies: View Best Answer
jordanlev replied on at Permalink Reply
It's a bit complicated. Are you a programmer? If so, I could try to explain how you'd go about it. Otherwise, I don't think it would be possible (if I wasn't so busy with other things I'd love to help you more with this, but unfortunately can't do so right now).
bridgetdesigns replied on at Permalink Reply
Hi Jordan, thanks for getting back to me. I am a front end designer/developer but I only have a basic knowledge of php. However I would like to have a go, if you dont mind pointing me in the right direction! If not I will check out the add ons and see if there is something I can buy that will help?
Many thanks
jordanlev replied on at Permalink Best Answer Reply
The hard way is to modify the block code so it lets you choose an attribute when you're in edit mode. But that's going to be *really* hard (for a non-programmer).

The easier (and hackier) solution is to copy the package 3 times, and change the directory names and package handles in the various files, so you have 3 different addons all doing the same thing but for different attributes. This requires that you go through the code with a fine-tooth comb and change everywhere you see something like "RelatedContent" or "related_content" or "Related Content" etc. etc. ... to something else (like "RelatedMachines" or "related_machines" or "Related Machines", etc. etc.).

You'll want to go into the top-level controller.php file (the package controller), AND all the files in the block (packages/related_content_links/blocks/related_content_links/) -- db.xml, edit.php, and controller.php. And maybe another one? (I can't remember off the top of my head).

Please please please if you do this, install yourself a fresh new test site to do it on -- do not do it on your live server until you've verified that you have them all working together. I guarantee that you *will* make mistakes along the way (because everyone always does, myself included) -- it's really hard not to miss every last instance that needs to be changed. So get it all working on a test site, then after it's all working, install the copies onto your live server (AFTER MAKING A DATABASE BACK UP OF YOUR LIVE SERVER).

Good luck!



PPS - Seriously, don't forget to make a backup first :)
bridgetdesigns replied on at Permalink Reply
Brilliant, thank you. I had thought that would be one way to do it (the hackier version) but wasn't sure if that would work and didn't want to jump in without checking! I will definately make a backup and try it out on a test site first dont worry! Thanks again for your help and I will let you know how I get on!

bridgetdesigns replied on at Permalink Reply
It worked! Managed to succesfully copy the orginal block, rename everything and now I can add attributes from different categories to one page and display them whereever I need. Thank you so much!!
jordanlev replied on at Permalink Reply
Nice job! Glad you got it working.
bridgetdesigns replied on at Permalink Reply
One other thing - this might be asking too much though!

Would it be possible to show a thumbnail in the page list for this block? I have thumbnails showing in the normal page list block and I was wondering if I could add something in to this that would do the same?
jordanlev replied on at Permalink Reply
Super easy (kind of) -- the block's view.php file is very similar to how the PageList block works.

Add this to the top of the block's view.php file (under the defined('C5_EXECUTE')..." line):
<?php $ih = Loader::helper('image'); ?>

Then add this under the "$date = empty($dateFormat) ? ..." line:
$img = $page->getAttribute('example_image_attribute_handle');
$thumb = $ih->getThumbnail($img, 64, 9999);

Note that the "64" is the max width, "9999" is the max height (setting it to that high number basically means "no max height"). You could also add a 4th argument of TRUE to crop the image instead of a proportional resize.

Finally, add the image output somewhere inside the "foreach ($pages as $page)" loop:
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />

And of course you will need to create the custom attribute for the thumbnail image (and change 'example_image_attribute_handle' in the code sample above to the handle you use for the new attribute).

For future reference, if you're running Concrete5.5 or higher, the page list block template includes sample code showing how to output an image attribute. I also have a slightly more detailed set of comments about what you can put in page list templates here:
bridgetdesigns replied on at Permalink Reply
Thanks again Jordan, hugely helpful! I am just learning Concrete5 and love it so far and it is really great to start learning how to make adjustments like this. Cheers!
bridgetdesigns replied on at Permalink Reply
Hi, sorry to keep asking questions but I am now trying to hard code this list into a template, rather than having to add them through the front end in blocks as there are loads of lists I need to show. I have found some documentation on how to do this but couldn't get it to work, I think because it is a custom block and I am not sure which options I need to pull out? Can any one point me in the right direction?
PassionForCreative replied on at Permalink Reply
if you are using version 5.5 use stacks and Global Areas. You could have 3 page types, all based on the same template but each calls a different stack.

If you are using an older version do the same thing with scrapbook blocks
bridgetdesigns replied on at Permalink Reply
Thank you I am new to Concrete5 and havent used global areas yet - I will investigate! Thanks.
jordanlev replied on at Permalink Reply
Hmm... if you're needing to hard-code this block, it might not be the right solution for your situation. Stephen's suggestion might work for you.

But it sounds like what you really need are "Page Defaults" -- put the blocks on the page defaults for a certain page type, and then every new page created of that type will have the block on it already.

If you still want to do the hard-coding thing, I'll have to go through the code to figure out how to do this (you can generally look to the db.xml file to see the available fields, but some of them require the data to be in a specific format that is not easily guessable). Let me know if you want this (although note I probably can't get to it for a while -- next week maybe).
bridgetdesigns replied on at Permalink Reply
Thanks for getting back to me. Basically what I am doing is adding a list that displays biographies in groups - by letter, country, machine and group type to different pages in a site. The main page for each section displays each list in turn so when you are on the Biographys by name page and select "a" for example it hides all the other lists and just shows people in the "a" category. I have got all that sorted out but it was a bit of a pain having to go into edit mode and add each list for each section by hand. I thought if I could just add them in the code it would have been quicker, but I've done it the long way now so no worries!

As a final thought is there a way to show all categories from one attribute on a page at the same time? At the moment I can add the block you gave me and select it to show one category, but is it possible to show them all?

Thanks for all your advice, it has been unbelivably helpful!

jordanlev replied on at Permalink Reply
Here is code for getting all of the available options in an attribute:
//Retrieve the attribute options...
$attrHandle = 'my_attribute_handle'; //<--Change this to your attribute's handle
$ak = CollectionAttributeKey::getByHandle($attrHandle);
$satc = new SelectAttributeTypeController(AttributeType::getByHandle('select'));
$options = $satc->getOptions();
//Now loop through the options and do whatever you want with them...
foreach ($options as $option) {
   echo $option->ID;
   echo $option->value;

You'll have to figure out how that integrates into the rest of your site though (it's totally dependent on how you have things set up and what you want it to look like, so unfortunately I can't give you a complete answer here).
bridgetdesigns replied on at Permalink Reply
got it working and its just what I need - that you so much! I feel I have learnt a huge amount about Concrete5 this week - thanks!
bridgetdesigns replied on at Permalink Reply
Arrgggh! All the custom blocks have stopped working except for one! everything was fine and then they just didn't work any more! Can't find anything wrong - the code it the same except for the attribute handle.