Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Wordpress Functions, Display Based On Category

  • Please log in to reply
3 replies to this topic

#1 AbleReach


    Peacekeeper Administrator

  • Hall Of Fame
  • 6471 posts

Posted 15 January 2012 - 06:06 PM

I'm looking for ways to customize groups of posts by category. I found two functions that look promising.

post_is_in_descendant_category can be used to see if a post is in a child category. If a post in the 'apples' category and 'apples' is a descendant of 'fruit', the post in the 'apples' category is a post in a descendant category.

cat_is_ancestor_of seems to do the same thing, exept it doesn't check the post, it checks the category.

I'm thinking that I could use post_is_in_descendant_category to plug in special values for categories that are outside of if it's fruit or not. For instance, if some 'apples' posts are also in a category called 'coupon-sale', I think I could say to pop in a star and a text box on those posts.

Then, cat_is_ancestor_of would be by logical grouping of categories... if it's an ancestor of 'fruit', of which 'tree-fruit' is a child and 'apples' is a subcategory, apply cat_is_ancestor_of to 'fruit' and the same stuff will be applied to 'tree-fruit' and 'apples'.

Do I have it so far?

Now, what if I have content that fits both conditions? What takes prescedence? How can I think through using both at the same time?

#2 Michael_Martinez


    Time Traveler Member

  • 1000 Post Club
  • 1354 posts

Posted 17 January 2012 - 09:28 PM

It depends on what you're trying to do. For example, I don't think I would use "post_is_in_descendant_category" because that implies to me that if you have a hierarchy of CATEGORY, Sub-Category-1 and Sub-Category-2, and Sub-Sub-Category-1A then everything in that hierarchy would be included in any function looking from CATEGORY on down.

This is how Wordpress displays posts in its categories, so you end up with duplicate listings. I would have preferred the option of NOT seeing my sub-category posts displayed in the main category listing but apparently they are using this "post_is_in_descendant_category" function to get ALL of the nodes hanging from the tree.

But if you want to append something to all the posts in a category trees (filtered by other criteria such as your "apples-only" example), then "post_is_in_descendant_category" looks like it would grab everything (except, maybe, articles published only under the root category).

Wordpress is still a little to linear for my tastes. I would like a default behavior that allows me to treat posts more like pages, in that I could specify which (and how many) category/sub-category listings I would show the posts in.

Maybe what I should have done was ignore my categories and just use tags. I could probably tweak things to do that.

In which case, maybe what you want is to use tags as well. But I would not publish both tags and categories on a Website these days. I would use one or the other.

#3 AbleReach


    Peacekeeper Administrator

  • Hall Of Fame
  • 6471 posts

Posted 18 January 2012 - 02:38 AM

Thanks, Michael.

This is for a national directory. There is software out there that is pre-built to do at least most of what I want, but, being me there will always be something I'd like to tweak. I also tend to build my own computers, for just that reason. It keeps me challenged and happy.

I've separated posts into two top level categories, "blog" and "directory." The blog "posts" gets the classic blog style content and only show up in the "blog" area. The directory "posts" will need custom styling and content and will show up only where designated in the "directory" children. They'll also get different sorts of sidebars. If you're looking at the listing for a place in Hometown, Your State, the "latest posts" listing will show the most recent listings for Hometown, unless there aren't any, in which case Hometown listings are followed by the most recent listings for Your State.

The directory "posts" will be in one category - their city - but they'll all be children of a State and the Directory. Because the number of cities are potentially unlimited, I can't just say show this, else this, else if this default thingy. That leaves me with making the city version of everything into the default and specifically defining everything else, or figuring out how to reliably pin down parents and children.

I've trended towards using categories for structure or logical grouping and tags for posts with the same sort of interest - eg a category might be "Internet Dating" with tags for "Mama told me not to come," "First date jitters" and "Reasons to wear a crazy hat." Love the option of applying multiple tags wily nily, though I think multiple categories per post are a SEO kiss of death. I've played with letting different flavors of archives be indexed and my conclusion is that it's usually good to either pick one and only one sort of archive to index, or index no archives. If you want to rank for "category name," write about it.

Free tip: If you want to try to get the archves for that "category name" to be a good result in the SERPS, top the archives page for that category with your very best evergreen resource guide to that category, then plug the arcives underneath as excerpts.

#4 Michael_Martinez


    Time Traveler Member

  • 1000 Post Club
  • 1354 posts

Posted 18 January 2012 - 01:37 PM

Yes, I agree that one should write a good description for category pages. Alas! Wordpress strips out the formatting. They are still mostly in the Land of Potential, I think, because there is much more yet that they can do without having to undo anything that they have done.

RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users