[SOLVED] Display 'select' attribute on blog posts

Permalink
Hi everyone...

I'm finishing up some details on my website and I want to 'explain' what current article is about (not a description, but a type). So I thought I could create a custom 'select' attribute.

For example, if I select "C5 Problems/Solutions", then the page should display the area marked in red in the attachment.

I'm currently using layouts for this, but adding it one by one is completely inefficient, so creating a custom block would not be my solution either. I believe it can be done with some php if statements, but I have no PHP knowledge, so I don't know where to start...

I'd like it to be compatible with C5 Composer too, since I use it to create my blog posts...

Any help would be greatly appreciated. Thanks in advance.

1 Attachment

NBardales
 
Mnkras replied on at Permalink Reply
Mnkras
I don't understand what you mean with marking the area in red, also, why not try using tags?
NBardales replied on at Permalink Reply
NBardales
I'm already using tags... But they're not what I mean by this... (see previous attachment).

I'm trying to use php 'if' statements and 'echo' right now... Will post my progress soon...
jordanlev replied on at Permalink Reply
jordanlev
Do you mean that you have several different pieces of content (one for each category), and you want one of those pieces of content to appear on the page based on the choice a user makes for the attribute?

If so, you will want to add some code to your theme template for the blog post page. What theme are you using, and do you know if the theme has a "blog_entry.php" template file?
NBardales replied on at Permalink Reply
NBardales
Exactly! Except, I want to select the attribute (not the user).
I'm trying to add some php 'if' statements, and echo the results... but I haven't tested that yet.

I'm using my own theme and yes, I do have that template file...
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Okay. The code would be like this:
<?php $category = trim($c->getAttribute('my_attribute_handle')); ?>
<?php if ($category == 'first category'): ?>
  <div class="whatever">
    PUT YOUR CONTENT FOR FIRST CATEGORY HERE
  </div>
<?php else if ($category == 'second category'): ?>
  <div class="whatever">
    PUT YOUR CONTENT FOR SECOND CATEGORY HERE
  </div>
<?php else if ($category == 'another category'): ?>
  <div class="whatever">
    PUT YOUR CONTENT FOR THIRD CATEGORY HERE
  </div>
<?php endif; ?>


I think to make it work you copy this file:
SITEROOT/concrete/page_types/blog_entry.php

...to here:
SITEROOT/page_types/blog_entry.php

(you may need to create the top-level "page_types" directory first). Then paste in the code I have above into that new copy of the blog_entry.php file.

Good luck!
NBardales replied on at Permalink Reply
NBardales
Amazing! Thank you so much, that did the trick!

I just had to change all 'else if' statements into 'elseif' (removed the space)

Now to add some CSS and move on...

Thanks again!