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.

Reverse relations and categories

September 23, 2008 5:29am

Subscribe [3]
  • #1 / Sep 23, 2008 5:29am

    mmmdreg

    6 posts

    Hi guys, I’m pretty new to EE but I love it. I have a problem I can’t seem to fix myself. It seems quite simple so perhaps you can help me out =)

    I have a bunch of publications with different authors and I’d like to be able to display the publications by a certain author. Therefore I have created a weblog for each publications and authors, with the publications having a custom relationship field to the author weblog. Furthermore, the publications are divided into multiple categories. Let’s just assume there are only 2 - books and magazines.

    The main page displays all publications sorted chronologically with all authors:

    Books
    -Publication1
    -Publication3

    Magazines
    -Publication2
    -Publication4

    The code for that is

    {exp:weblog:categories weblog="lab_publications" style="linear"}
    
        <h2>{category_name}</h2>
    
    <p>    {exp:weblog:entries weblog="lab_publications" orderby="date" category="{category_id}"}<br />
            {publications_text}<br />
        {/exp:weblog:entries}</p>
    
    <p>{/exp:weblog:categories}

    and it works just fine.

    The code I have for what I’d like to implement, however, does not work fine. It is:

    {exp:weblog:categories weblog="lab_publications" style="linear"}
        <h2>{category_name}</h2>
    
    <p>    {exp:weblog:entries weblog="lab_people" orderby="date"}<br />
            {reverse_related_entries orderby="date" sort="desc" category="{category_id"}} <br />
                 {publications_text}<br />
            {/reverse_related_entries}<br />
        {/exp:weblog:entries}<br />
    {/exp:weblog:categories}

    It gets all the correct entries but publishes them as

    Books:
    -Publication1
    -Publication2

    Magazines:
    -Publication1
    -Publication2

    ie.. it outputs a duplicate list. Does this mean the category parameter is not being parsed in the reverse relation block?

    Your help would be much appreciated.

    George

  • #2 / Sep 23, 2008 9:49am

    Boyink!

    5011 posts

    Category is not a parameter available to the reverse_related_entries tag.

    In the second example now you’ve nested tags, but have removed any link between them as in the first.

    I’m not sure if you’ve simplified the code for the sake of the example, but I don’t see where you’re pulling author information in the second example.

    Does your goal of displaying all pubs by a specific author include the need for category info?

  • #3 / Sep 23, 2008 1:34pm

    tbritton

    714 posts

    Glen Swinfield posted an extension and tiny hack that extends the relationship tags to include all weblog:entries parameters, so it may work with categories.

    Here is the post.

    He says:

    Getting the full functionality of the weblog entries tag for related and reverse related entries is easy, with a small extension and an even smaller hack.

    Let me know if you try it and it works for you!

    Terry

  • #4 / Sep 25, 2008 8:04pm

    mmmdreg

    6 posts

    I’m not sure if you’ve simplified the code for the sake of the example, but I don’t see where you’re pulling author information in the second example.

    Does your goal of displaying all pubs by a specific author include the need for category info?

    Sorry I should have specified - it’s dynamic through the url.

    I initially did want the “all publications by author” sorted into categories but in the end it’s turned out better without it. However, I can think of situations where categories in reverse related entries would be useful. I think it’s been brought up before as a feature request.

    On another new note, in an entirely different template, I want to display one piece of text if any reverse entries exist, and another piece if there are none.. but I can’t figure this one out. Would you know of a variable I can use in an if statement perhaps?

    Good job on all the boyink stuff btw.. that’s where I learnt EE =)

    Terry -thanks for the info but I won’t be using it for now. If the need arises then it’ll definitely be the first place I look.

  • #5 / Sep 26, 2008 9:43am

    Boyink!

    5011 posts

    There is a if_no_reverse_related_entries conditional available - it’s on the docs page for the reverse related entries page.

  • #6 / Oct 10, 2008 7:34am

    mmmdreg

    6 posts

    To somewhat extend on the issue,

    //deleted stuff as it was no longer relevant and would cause confusion

    1) Aside from workarounds such as duplicating the category in a custom weblog field or plugins, will it become possible to display reverse entries in categories in the future at some point?
    2) I read that pagination of reverse entries is not supported. Is this true and will it be supported at some point if so?

    Thanks for your work guys =)

    George

  • #7 / Oct 10, 2008 11:26pm

    mmmdreg

    6 posts

    Solution to myself, part 1:

    Title one (Hardcoded title)
    <ul>
    {reverse_related_entries weblog="lab_publications" orderby="date" sort="desc"}
        {categories}
            {if category_id=="1"}
                {body}
            {/if}
        {/categories}
    {/reverse_related_entries}
    </ul>
    
    Title 2 (Hardcoded title)
    <ul>
    {reverse_related_entries weblog="lab_publications" orderby="date" sort="desc"}
        {categories}
            {if category_id=="2"}
                {body}
            {/if}
        {/categories}
    {/reverse_related_entries}
    </ul>
    
    etc.. etc.. repeat for other categories

    This is not as elegant as it could be unless I’m missing something but it’ll do for now!

  • #8 / Oct 11, 2008 4:30am

    tbritton

    714 posts

    This is not as elegant as it could be unless I’m missing something but it’ll do for now!

    This seems plenty elegant to me!! Very nice solution!

    Terry

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

ExpressionEngine News!

#eecms, #events, #releases