0

I've read a few tutorials on how to use blog categories in conjunction with Structure. Is there a way to do this without Structure?

I've never used categories before. Any thoughts on displaying results for categories?

Typically do the following for displaying entries... Something similar for categories?

{exp:channel:entries channel="blog_entry|blog_link|blog_photo|blog_quote|blog_video" search:title_permalink="{segment_2}" limit="1" dynamic="yes"}
  • Do you need the search:title_permalink="{segment_2}" parameter? Surely the dynamic="yes" will take care of that. – foamcow Jul 9 '14 at 8:44
3

It's actually easier than with Structure. There's a URL breaking word that you set in Admin->Channel Administration->Global Preferences. By default, it's set to "category", which means that when it encounters a URL with /category/ as a slug, it treats the part after category/ as a slug for a category, so /category/holiday would treat "holiday" as the category slug.

Once you have the slug, an add-on like http://gotolow.com/addons/low-seg2cat would let you get the category ID from the slug, then just put that into your channel entries loop like so:

    {exp:channel:entries 
        channel="blog_entry|blog_link|blog_photo|blog_quote|blog_video" 
        category="{segment_3_category_id}"}
| improve this answer | |
  • Thanks! I've done just about everything else in EE. Just haven't had much need for categories till recent. I'll give it a shot and let you know how it goes. Thanks, again! – Justin Meyers Jul 8 '14 at 22:21
  • Currently, it's returning: blog/blog-article/C5. One of the categories will return one entry , but other entries sharing the same category will not show up or any other category for that fact. – Justin Meyers Jul 8 '14 at 23:13
  • Also, for clarification, each blog type is it's own channel. I made the categories available to each channel. – Justin Meyers Jul 8 '14 at 23:21
  • Not 100% sure without trying it out, but try out dynamic="no" and parse="inward" in your channel entries loop. It may have to parse the Seg2Cat plugin first. – jpea Jul 9 '14 at 13:30
  • You won't need the parse="inward" for Seg2Cat's sake. It parses early and becomes a global variable. @Justin, I think the issue lies in how you're building your category URLs. Make sure that if you are using {segment_3_category_id} that segment_3 actually contains your category's category_url_title. – Alex Kendrick Jul 9 '14 at 15:35
0

@AlexKendrick and @ jpea - You guys really helped me figure this out. Really appreciate the help.

I just had to set some appropriate category parameters for the template group that users are routed to after select a blog hyperlink.

Works great.

| improve this answer | |
0

jpea's answer here is spot on, but since you asked me for more help, Justin, here is a pared-down example of how I build my category links and then filter the entries. There are lots of other ways to do this, though.

In a template somewhere, generate your category links:

<ul>
    {exp:channel:categories channel="blog" disable="category_fields" show_empty="no" style="linear"}
        <li><a href="/blog/category/{category_url_title}">{category_name}</a></li>
    {/exp:channel:categories}
</ul>

Then in your blog listing template where you display your posts (blog.group/index.html), set your channel:entries loop up like this. You will need to have LowSeg2Cat installed and enabled.

<h1>Blog{if segment_2 == "category"} Category: {segment_3_category_name}{/if}</h1>

{exp:channel:entries
    channel="blog"
    disable="categories|category_fields|member_data|pagination"
    dynamic="no"
    {if segment_2 == "category"}
        category="{segment_3_category_id}"
    {/if}
}

    <h2>{title}</h2>

{/exp:channel:entries}

Note the simple conditional in the channel:entries parameters that checks for the presence of a category filter. If you are not filtering by categories then it will just display an unfiltered list of all blog entries.

| improve this answer | |
  • Thank you for taking the time to explain this in more detail. Much appreciated. I'll give it a shot and let you guys know how it goes! – Justin Meyers Jul 10 '14 at 17:15
  • Any reason it would go from showing all the available categories to only showing one? – Justin Meyers Jul 10 '14 at 18:04
  • 1
    Most likely because you only have 1 entry assigned to a category. In the example, show_empty="no" means that it'll only pull entries that have at least 1 category (any category) assigned to them. – jpea Jul 10 '14 at 18:05
  • Exactly as @jpea said, the show_empty parameter will prevent listing a category that has no entries assigned to it. PS I edited my answer to fix a type in the content of the h1 tag. – Alex Kendrick Jul 10 '14 at 18:07
  • @AlexKendrick - Thanks! Yes, that makes sense! Definitely learned something :) All categories are resolving to the exact same blog post. This particular blog post only has one category assigned to it, but is the only entry displayed for all categories. Think I might know the issue. Let me give it a stab. Really appreciate you guys going out of your way for some direction! – Justin Meyers Jul 10 '14 at 22:26

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.