1

I’m new at Craft CMS and I hope someone of you could help me a little. At the moment I get all entries from my blog by

{% paginate craft.entries.section('blogItem').limit(globalSettings.postsPerPage) as pageActive, pageEntrys %}

Actually I have 5 categories (catA, catB, catC, catD, catE) at one level, but now I have another category Nr. 6. (catF) All 5 categories are shown at the blogpage, but catF sound just shown at an separate page (pageF).

I did not find a way to hide all entries from catF at the blogpage and just show these entries at pageF.

Thy four your help. smueller

3

New Answer based on our discussion:

<!-- Step 1. get the category you want to exclude
     since I still don't know your structure I'll just grab it
     per id. You can see that in your cp edit url (the last number) -->
{% set category = craft.categories.id(108).first() %}

<!-- Step 2. get all entryIds related to that category -->
<!-- this should be an array of ids you can dump it to check them -->
{% set entriesInCategory = craft.entries.relatedTo(category).ids() %}

<!-- Step 3 exclude those ids from your last query -->
{% set entries = craft.entries.section('blogItem').id('and, not ' ~ entriesInCategory|join(', not ')) %}

<!-- just for debugging and testing if these are the correct one -->
{% for entry in entries %}
    {{ entry.title }}<br>
{% endfor %}
<!-- then you can use your paginate with those entries -->

old Post

You can grab all entries that are related to category F and exclude them in your query

{% set catF = craft.categories.group('categories').ids() %}
{% set entriesForCatF = craft.entries({
    relatedTo: catF,
}).ids() %}

{% set entriesNotInCategoryF = craft.entries.section('blogItem').id('and, not ' ~ entriesForCatF |join(', not ')).ids() %}


{% paginate craft.entries.section('blogItem').limit(globalSettings.postsPerPage).id('and, not ' ~ entriesNotInCategoryF |join(', not ')) as pageActive, pageEntrys %}
  • Hey, thx for your help. i changed each "CategoryF" and "CatF" by the real category name and i changed the "categories" in categories.group. "blogItem" could stay. But it wount work for me. All i get is a clear div, without blogitems or errors. – SMueller Oct 23 '17 at 9:13
  • can you debug every variable and tell me whats in there? just use {{dump(variableName)}} Because for me the code works – Robin Schambach Oct 23 '17 at 9:16
  • Hope that will help: {{ dump(catF) }} array(5) { [0]=> string(1) "4" [1]=> string(1) "5" [2]=> string(1) "6" [3]=> string(1) "7" [4]=> string(2) "36" } ` {{ dump(entriesForCatF) }} array(5) { [0]=> string(2) "37" [1]=> string(2) "13" [2]=> string(2) "10" [3]=> string(2) "11" [4]=> string(1) "9" }` – SMueller Oct 23 '17 at 9:47
  • `{{ dump(entriesNotInCategoryF) }} object(Craft\ElementCriteriaModel)#196 (17) { ["strictAttributes":protected]=> bool(false) ["_elementType":"Craft\ElementCriteriaModel":private]=> object(Craft\EntryElementType)#146 (7) { ["componentType":protected]=> string(11) "ElementType" ["_sourcesByContext":"Craft\BaseElementType":private]=> NULL ["_classHandle":"Craft\BaseComponentType":private]=> NULL ["behaviors"]=> array(0) { } ["_initialized":"CApplicationComponent" I had to shorte this: too long by 7303 characters – SMueller Oct 23 '17 at 9:49
  • I tried and testet some more time to use your code, but i cant find the position where i have to set the name or the id of the "hidden category", called catF in my example. CatF: shows all ids from all categories entriesForCatF: shows all Ids from all entries entriesNotInCategoryF: shows 'array(0) { } ' – SMueller Oct 23 '17 at 11:45

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.