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.

Omitting an entry based on two conditions

May 28, 2011 3:42pm

Subscribe [5]
  • #1 / May 28, 2011 3:42pm

    natis

    3 posts

    Hi all,

    I have a news-esque blog under development and I have a situation where I need to omit an entry based on two conditions. At the top of the page is a featured article. The featured article is not necessarily the latest article and the client indicates an article as being a feature by assigning it a category. Below the featured article is the list of all the other articles on the blog.  The issue that comes up is when the client adds a new featured article, then the article appears twice; once in the featured article spot and immediately below the featured article in the list of articles. What I’m looking to do is omit a featured article from the standard list only if it’s the latest featured article. Offset doesn’t work since it applies to all articles. So in essence I’m looking for something that is like “offset 1 from category_group”.

    Any insights are greatly appreciated.

    Thank you,
    —jj

  • #2 / May 28, 2011 4:15pm

    Rob Allen

    3118 posts

    If you’re using categories to trigger this then you can omit any category from the output by using the category= parameter.

    In this example the first Channel tag only shows items from category ID 1, the second shows all items except from category ID1…

    {exp:channel:entries channel="blog" category="1"}
    {title}
    {/exp:channel:entries}
    
    {exp:channel:entries channel="blog" category="not 1"}
    {title}
    {/exp:channel:entries}
  • #3 / May 28, 2011 4:21pm

    natis

    3 posts

    Hi Rob,

    Thank you for the quick response but this would prevent all items marked as a featured article from appearing in the list. I need to omit only the latest featured article from the list, not all of them.

    —jj

  • #4 / May 28, 2011 6:13pm

    Rob Allen

    3118 posts

    Hmm the only way I can think of is to use a custom Status…

  • #5 / May 28, 2011 7:20pm

    You’ll probably have to mix in a bit of raw php to get around parse order funkiness.

    Here’s a much-reduced example from a 1.x news site:

    {exp:weblog:entries category="99" limit="1" status="Open"}
        
        <? $skip_id = "{entry_id}"; ?>
    
        {assign_variable:skip_id="<? echo $skip_id;?>"}
    
        /stuff/
    
    {/exp:weblog:entries}
    
    {embed="includes/otherstories" skip_id="{skip_id}"}

    and

    {exp:weblog:entries status="Open" limit="15" entry_id="not {embed:skip_id}"}
    
        /stuff/
    
    {/exp:weblog:entries}

    I pass a few other variables to control weblogs and categories, but you can see the general idea.

  • #6 / May 28, 2011 7:51pm

    Mark Bowen

    12637 posts

    I might be misunderstanding what’s needed here but if you are using url_titles then you could just do something like this :

    {exp:weblog:entries
        weblog="default_site"
        url_title="not {segment_3}"
        dynamic="off"
        sort="asc"
        disable="member_data|pagination|categories"}
    
    {title}
    
    {/exp:weblog:entries}

    That should bring back entries except for the one which is currently being viewed. You would need to change {segment_3} above if your url_title is somewhere else in the URL but that should work.

    Don’t know if that helps at all?

    Best wishes,

    Mark

  • #7 / May 28, 2011 8:28pm

    Marks example will work for a single-entry page, mine’ll work for, say, a news section index page.

  • #8 / May 28, 2011 9:01pm

    Kernon

    173 posts

    Dylan,

    In the first set of code, is PHP set to parse on output?  If not, I can’t see how the entry_id would have the right value.  But, if it is parsed on output, how does the EE assign_variable work?  What I mean is, I would have thought that parsing PHP on output would mean that EE constructs like assign_variable would have already been processed.

  • #9 / May 28, 2011 11:05pm

    The php output setting doesn’t affect the native EE parsing, to the best of my knowledge. It’s a switch for the raw php processing. This template’s set for “output” and works fine for me.

    The whole “setting of a php variable with EE output, assigning an EE variable w/ that, and using it in an embed” trick is something I find I have to do quite often to accomplish what I want. There’s probably a much better way to get around these parse order hurdles, but not that I’ve found.

  • #10 / May 28, 2011 11:48pm

    Kernon

    173 posts

    I guess I wasn’t being clear—I didn’t mean to suggest that PHP parsing stage would directly affect EE tag parsing, but rather I thought that the assign_variable would be parsed before the PHP.  This is what I gathered from the documentation.  Nor am I suggesting that this doesn’t work—- I am just trying to reconcile it with the documentation.

  • #11 / May 29, 2011 3:05am

    Wasn’t there a bit of a change on the timing for variable assignment between 1.x and 2.x? I don’t know if this method is valid for 2.x; I’m still waiting for a few bugs to be stepped on and modules to get ported over to delve into it.

    I don’t remember where I first tracked this technique down - I wish I could give credit properly - but I use it all over the place.

  • #12 / May 31, 2011 4:02pm

    natis

    3 posts

    Thanks for the response Dylan. I started playing around with that and I wasn’t getting it to work, but then it made me realize that I could do it with Jquery. I add a class to the div that contains the news story and hide the first instance of that classed div. Not elegant but ultimately it does what the client is looking for.

    Thank you,
    —jj

  • #13 / Jun 03, 2011 12:40am

    Roger Glenn

    54 posts

    In my experience it’s much easier to implement this kind of behavior/control over “featured” items using custom statuses, just as bluedreamer suggested.

    You’d use something like this in your channel entries tag for the featured article at the top…

    {exp:channel:entries ... status="featured"}

    ...and this for the other “non-featured” articles

    {exp:channel:entries ... status="not featured"}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases