5

I am using ExpressionEngine 2.5.2

I have a website that includes a featured blog post at the top, as well as a news section that all of my blog posts in chronological order. When a blog post is featured at the top of my homepage, I would like it to be excluded from the list of blog posts in the news section. In order for it to show up in the featured space, I have created a category with an ID of 440 titled Featured Post. For the News section, I am using a the ExpressionEngine channel:entries tag and am using category parameter with the "not" variable in order to exclude posts with the category of Featured Post. However the featured post is still showing up in the news section. Can someone see anything I am doing wrong here?:

 {exp:channel:entries  channel="news" orderby="date"  limit="9" category="not 440"}             
     <div class="holder">
        <a href="{post_url}">
             <img src="{post_image}" width="336" height="195" alt="Post Hero" />
        </a>
        <div class="info">
            <h3><a href="#">{title}</a></h3>
        </div>
     </div>
  {/exp:channel:entries}    
  • Looks ok to me. A few things to check: Is the featured entry categorized correctly? Do you have the category id (440) correct? Also, your code example here does not show it, but it is worth double checking you don't have disable="categories" as a parameter on your channel:entries tag. – Alex Kendrick Jan 29 '13 at 2:28
  • 1
    FYI Alex, pretty sure that disabling categories via a parameter does not prevent one from using the various category-related parameters. It just doesn't fetch the actual data in the query. – Derek Hogue Jan 29 '13 at 3:52
8

This parameter is confusing, and has been the subject of much consternation. As per Travis' comment on the docs page:

If an entry is in two categories, cat_id 1 and cat_id 2, and you ask for just entries with category="not 1", the entry will still show up in the output. This is because it is in category 2. This may not be the behavior you expect.

Also see this bug report, closed as "not a bug", as I suppose it is intended behaviour. There used to be a good feature request thread in the EL forums with ideas for implementing some sort of "cannot be in this category no mater what" parameter, but that forum section is now gone, and thus the feature request with it.

So, in other words, your code is working as intended.

I would suggest using a custom Status instead - it will work as you intend, and will be easier for your client to see at a glance which entry is featured that way from the Edit Entries screen as well.

| improve this answer | |
  • Hi Derek - I took your suggestion and instead including the categories parameter, I created a custom status. this was great, thanks! – jennetcetera Jan 29 '13 at 18:39
1

Would http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#offset

offset='1'

Do the job? Basically tell the display to ignore the first entry

| improve this answer | |
1

There's probably a better way to do this, using Stash, but in an EE 1.x site where I had this problem, I created a variable to hold the entry_id that needed skipping, and then excluded that entry from the entries call for the rest of the list.

There was some raw php involved, and an embed, iirc, to jump around some parse order issues.

| improve this answer | |
1

Derek did a good job answering the question and also proposed a good solution, but to just to give a bit more information. I also asked this question on the old EE forums. My solution was to limit the categories to a certain group and then be sure only one category from that group was applied. So something along the lines of:

 {exp:channel:entries channel="news" orderby="date" limit="9" category="not 440" category_group="1"}  

Obviously, this isn't perfect if you need multiple categories in the same group applied. Other suggestions on the previous thread were a custom field search and a custom query.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.