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.

if related categories == 0

June 22, 2007 5:02pm

Subscribe [1]
  • #1 / Jun 22, 2007 5:02pm

    Deron Sizemore

    1033 posts

    At the end of each blog entry, I’ve got this code:

    <h3>Related Posts</h3>
    <p>            <ul class="related"><br />
                {exp:weblog:entries related_categories_mode="on" limit="5"}<br />
                <li><a href="http://{title_permalink=blog/article}" title="{title}">{title}</a></li> <br />
                {/exp:weblog:entries}<br />
                </ul>

    Is there an easy way to say if related_categories == “0” then display “no related categories”

    As it is right now, if there are not related categories, all the user sees is the h3 heading “Related Posts,” but there are no entries in the list.

  • #2 / Jun 22, 2007 9:24pm

    Derek Jones

    7561 posts

    {exp:weblog:entries related_categories_mode="on" limit="5"}
    {if count == 1}
    <h3>Related Posts</h3>
    <p>    <ul><br />
    {/if}<br />
            <li><a href="http://{title_permalink=blog/article}" title="{title}">{title}</a></li> <br />
    {if count == total_results}<br />
        </ul><br />
    {/if}<br />
    {/exp:weblog:entries}

  • #3 / Jun 22, 2007 10:41pm

    Deron Sizemore

    1033 posts

    Ah my good friend Derek, who’s always there to the rescue on all my questions!  😊 

    My problem was that nesting everything like this, it outputted the heading “Related Posts” for each list item.  I know that the purpose of if count == 1 is to only show the heading once, but I’m not really following. It seems that it would only show the heading “Related Posts” when the total count of related posts were “1.” 

    Then, I’m not sure how the total_results works.  I know it displays the total number of entries, but not sure how it ties everything together with having the conditional around the closing < /ul >?

  • #4 / Jun 22, 2007 10:53pm

    Lisa Wess

    20502 posts

    Hi, Deron—No, if it were using total_results it would be as you describe, but {count} is the count of each entry - so the first entry is 1, the second is 2, etc.  So if count equals 1 will only show the heading if the entry count is one, thus giving you the heading you desire. =)

  • #5 / Jun 23, 2007 5:42pm

    Deron Sizemore

    1033 posts

    I see.  I changed the “1” to “2” and saw that it changed the H3 heading to the second entry instead of the first entry.  Makes sense.

    The only other thing that isn’t quite clear is that I wrapped the first conditional around the H3 tag as well as the < ul >.

    <h3>Related Posts</h3>
    <p><ul class="related"><br />
    {/if}

    and then I wrapped the second conditional around the closing < /ul >.

    {if count == total_results}
    </ul>
    {/if}

    Not sure why they needed to be wrapped around those particular items?

  • #6 / Jun 23, 2007 5:53pm

    Derek Jones

    7561 posts

    You only want the opening and closing tag for the unordered list to appear once.  Using these count conditionals allows you to place them within your weblog entries tag, so no markup will be output at all unless there are entries to display.

  • #7 / Jun 23, 2007 10:35pm

    Deron Sizemore

    1033 posts

    You only want the opening and closing tag for the unordered list to appear once.  Using these count conditionals allows you to place them within your weblog entries tag, so no markup will be output at all unless there are entries to display.

    Ohh, I see. This is fixing a problem that I run into frequently it seems, just didn’t know how to get around it.  Now I do.  😊

    Thank you both

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases