开发者

Multiple Categories in Expression Engine

Ok, so, I have a lot of articles classified in multiple categories across my site. Let's say I have a category page for Atlanta where it lists all articles classified in Atlanta. In the sidebar, I'd like to show only the categories where there is an article classified as Atlanta AND whatever other category. Does that make sense?

I'm trying to do this without having to write a custom plugin that does this f开发者_开发知识库or me. Just am not sure if there is a way


Yeah, you just do this:

category="3&7&8"

http://expressionengine.com/user_guide/modules/channel/parameters.html#par_category

I personally hate EEs categories though. The way I'd do it is to use Playa. This plugin is well worth it. So instead of using EE categories, you create a channel of all your categories (cities). Then you create a playa field in your Articles channel, which allows you to select multiple cities. Then in your template, you just write an if statement:

{if cities="Atlanta && Sheboygan"}//DO SOMETHING{/if}


When you say "whatever other category" do you mean "at least one other category"? Or something else?


I'm not aware of an automagic way to do what you want, but EE is quite flexible -- there is always a way. In this case, the best way will probably be found on devot-ee. The second best way may be found in the examples below. ;)

{exp:channel:entries}

<h2>This is an entry called "{title}".</h2>

<p>All of its categories are: 
{categories backspace="3"}
  <a href="{path="site_index"}">{category_name}</a>, 
{/categories}
</p>

<p>The category in the URL is:
{exp:channel:category_heading channel="{channel_short_name}"}
  <a href="{site_url}/category/{category_url_title}">{category_name}</a>
{/exp:channel:category_heading}
</p>

<p>Excluding the category in the URL, its categories are:
{exp:query sql="SELECT cc.cat_url_title curl, cc.cat_name cname FROM exp_category_posts cp, exp_categories cc WHERE cc.cat_url_title != '{segment_2}' AND cp.entry_id = '{entry_id}' AND cp.cat_id = cc.cat_id" backspace="3"}
  <a href="{site_url}/category/{curl}">{cname}</a>, 
{/exp:query}
</p>

{/exp:channel:entries}

Please note, these examples assume a little bit about the structure of your site. Adjustment will probably be necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜