ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditional to test if entry has category

September 26, 2008 8:31pm

Subscribe [2]
  • #1 / Sep 26, 2008 8:31pm

    Sacha

    33 posts

    In order to display the current entry title in the title bar, I use something like this:

    {exp:weblog:entries weblog="articles" limit="1"}
    
    {embed="includes/head" my_title="{title}"}
    
    ...

    Where “head” is a template that contains all the <head> code, and uses the embedded variable as the page’s title. I don’t know if this is the “correct” way to do this, or if EE has a dedicated function, but up to now it works fine.

    But now I’m looking to add the current category to the title, when applicable.

    I tried using the following code:

    {exp:weblog:entries weblog="articles" limit="1"}
    
    {categories limit="1"}
    {embed="includes/head" my_title="{category_name}: {title}"}
    {/categories}
    
    ...

    But this doesn’t work when the entry has no category asigned to it.

    Is there a conditional to check if an entry belongs to one or more categories ? Or another way to fix this ?

  • #2 / Oct 15, 2008 10:01pm

    Sacha

    33 posts

    Any help with this ? maybe the original post is not clear enough ?

  • #3 / Oct 16, 2008 8:02am

    BridgingUnit

    214 posts

    Could you not separate things out? e.g.

    {exp:weblog:entries weblog="articles" limit="1"}
    
    {embed="includes/head" my_title="{categories limit='1'}{category_name}{/categories}: {title}"}
    ...
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases