Display Content that has been assigned a custom Category Attribute

Permalink
Hi, I am just wondering, like Wordpress if you are able to switch out feeds of content (say down a sidebar) based on the the idea that a custom category attribute has been assigned to it?

I have files and pages that will be assigned categories (1,2,3,4) as IDs and want to only show those lists when the parent page has been assigned an above ID so:

Page: Category 1 - Feed Category 2 List of files and pages in the sidebar.
Page: Category 2 - Feed Category 4 List of files and pages in the sidebar.

In my custom attribute, I have the ID and a customLabel which I would want to display along with the link to the files or page.

I've scoured the web, C5 documentation and cannot find a lead into how this could be done. I'm jumping in on a C5 task for this, working with Wordpress in the past, I can achieve this, so thought we might be able to do something equally brilliant in C5?

View Replies: View Best Answer
hutman replied on at Permalink Reply
hutman
I think you would just need to build a custom block that you put on all the pages which checks the page attribute then shows something, whether it be a stack or whatever else.

Something like
$c = Page::getCurrentPage();
switch($c->getAttribute('category')){
   case 1:
      //do things for case 1
      break;
}
BenSegniPH replied on at Permalink Reply
Hi Hutman,

thanks for this! This is working nicely. Not quite there yet, but beginning to see light at the end of the tunnel.

I have set up the custom block, this is installed and my switch is showing alternative content based on the page category attribute, I have assigned to it.

Great start. I normally work with Wordpress, so this task, I'm finding my feet with. If I want to pull in pages and files that have a certain category ID, is there a property that can do that?

I'm looking through here and can't seem to find anything.

https://documentation.concrete5.org/developers/working-with-pages/ge...

Thanks again!
hutman replied on at Permalink Best Answer Reply
hutman
I think you want to use the PageList -https://documentation.concrete5.org/developers/working-with-pages/se...

With the filterByAttribute.
BenSegniPH replied on at Permalink Reply
I found that this gets something more relevant back:

$list->filterByCategoryType(3);

I have 4 categories and this seems to bring back the page with this attribute assigned to it. Going to play about now with the Page object and see what I can get out of it.

Thanks, this is great help!!!!