295 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Beta Tester
+3 more
AkinGn
says

Hi, right now I’m excluding the portfolio category while retrieving the last blog posts to relevant section @ home page via a code that uses the variable:

$lastposts = get_posts('cat=-1')
1 is the ID of portfolio, but I wonder if there’s a way to exclude the portfolio category with its slug?
1383 posts
  • 5 Years of Membership
  • Affiliate Level 2
  • Collector Level 2
  • Exclusive Author
+1 more
wpCanyonThemes
says

I don’t think you can exclude by slug, but you can do a query to find the category id by it’s slug, and then use that id to exclude it.

But i think the best way to do blog post and portfolio post separation is to create a custom post type for portfolio posts. It will be easier for the theme user to add/delete/modify and it will be easier for you to code it, since you will have to exclude the portfolio category quite often (blog categories listing, archives, widgets like recent posts…) if you don’t use custom post type.

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says

Why do you have cat=-1? I think you’re looking for exclude=1… And anyways, I’m not sure if this is possible, but you may be able to find a plugin for it.

1383 posts
  • 5 Years of Membership
  • Affiliate Level 2
  • Collector Level 2
  • Exclusive Author
+1 more
wpCanyonThemes
says

@landow

Putting a negative number in the cat parameter will exclude that category.

A plugin? For such a simple thing? No.

2067 posts
  • Collector Level 3
  • 5 Years of Membership
  • Exclusive Author
  • United States
Landonw
says

Which is why it’s pointless to do so, and preferred to do ‘exclude=1’. And if he REALLY wants it, yes, if a plugin really is necessary.

I’m sure he won’t need to use a plugin though, he could probably do a special query.

295 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Beta Tester
+3 more
AkinGn
says

I don’t think you can exclude by slug, but you can do a query to find the category id by it’s slug, and then use that id to exclude it. But i think the best way to do blog post and portfolio post separation is to create a custom post type for portfolio posts. It will be easier for the theme user to add/delete/modify and it will be easier for you to code it, since you will have to exclude the portfolio category quite often (blog categories listing, archives, widgets like recent posts…) if you don’t use custom post type.

Thanks man, I’ll see about that. And thanks for your suggestion too, landonw.

by
by
by
by
by
by