2

I've been trying for days to figure this thing out. I'm building a News section in the site, and under news are 3 categories: Updates, Events, Archive. When you click on one of the categories, i want it to list all the entries where it is under that category, but no matter what I try I just get a 404 error.

Here are my settings: Channel short name: news Group Assignments > Category group: News Category Group Name: News News Categories: updates, events, archive

And here is my current code (though I've tried many many different options and version:

<!DOCTYPE html>
<html>
  <head>
      <meta charset="UTF-8">
      {embed="Pages/styles"}
      {embed="Pages/scripts"}
      {exp:channel:entries channel="news" dynamic="no" limit="1"}
      <title>{site_name} - {structure:page:title}</title>
      <meta name='keywords' content='{news-keywords}' />
      <meta name='description' content='{news-description}' />
      {/exp:channel:entries}
  </head>
  <body>
      {embed="Pages/header"}
      <main>
          <nav id="breadcrumbs">{exp:structure:breadcrumb inc_home="no" here_as_title="yes" separator=":"}{/exp:structure:breadcrumb}</nav>
          {exp:channel:entries channel="news" category="{segment_2_category_id}" dynamic="no"}
              <article>
                  <h1>{title}</h1>
                  <p>Author: {author} Posted: {entry_date format="%M %j, %Y"} at {entry_date format='%h:%i %A'}</p>
                  <p>{news-content}</p>
              </article>
          {/exp:channel:entries}
          <aside>
              <ul>
                  <li>Categories</li>
                  {exp:channel:categories channel="news" style="linear"}
                  <li><a href="{path='news/{category_url_title}'}">{category_name}</a></li>
                  {/exp:channel:categories}
              </ul>
          </aside>
      </main>
      {embed="Pages/footer}
  </body>
</html>

1 Answer 1

1

The channel:entries tag doesn't have a category_url_title parameter. If you want to use the URL structure you're after, you'll need to install Low Seg2Cat. Once installed, you can use {segment_2_category_id} to get the right category ID associated with the second segment (which points to a category URL title). Add dynamic="no" to the tag as well, since you're telling EE what to display, instead of letting EE guess, based on the URI.

Also, you're missing a closing quote on your opening tag. And I think you need to add style="linear" to your channel:categories tag, in order to avoid nested <li> elements.

So, with Low Seg2Cat installed, this is how it should look:

{exp:channel:entries channel="news" category="{segment_2_category_id}" dynamic="no"}
    <article>
        <h1>{title}</h1>
        <p>Author: {author} Posted: {entry_date format="%M %j, %Y"} at {entry_date format='%h:%i %A'}</p>
        <p>{news-content}</p>
    </article>
{/exp:channel:entries}
<aside>
    <ul>
        <li>Categories</li>
        {exp:channel:categories channel="news" style="linear"}
        <li><a href="{path='news/{category_url_title}'}">{category_name}</a></li>
        {/exp:channel:categories}
    </ul>
</aside>
5
  • Thanks for your help. But I'm still getting the "Status: 404 Page Not Found" error. I actually already installed Low Seg2Cat, and I've left its settings to its default.
    – Noah Yamen
    Feb 12, 2014 at 15:17
  • I should also mention that if I manually enter in a category's id (instead of {segment_2_category_id}) it will list the entries there. It's just not pulling the information via segment2 in the url. Here is the site I'm testing it on: oneoffs.co/news Yes, the site is only the bare-bones of code, just building a template for functionality so far. I've just updated my original post to reflect my current code.
    – Noah Yamen
    Feb 12, 2014 at 15:23
  • Ah, you're using Structure. That changes the way URI segments work. You'll need to make the second segment after news capable of being dynamic. I'm no Structure expert, so I don't know where/how to do that.
    – Low
    Feb 12, 2014 at 15:31
  • I am using Structure, yes.
    – Noah Yamen
    Feb 12, 2014 at 15:37
  • Thanks, this gives me something to investigate some more.
    – Noah Yamen
    Feb 12, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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