0

I have a lot of Pages which can be (need to be) grouped under a number of different Categories. ** Then the more important thing is, i need to control those pages (of different groups) programatically via functions.php.

Lets say, i would have:

  • Page A (Categorized as: Fruits)
  • Page B (Categorized as: Vehicles)
  • Page C (Categorized as: Vehicles)
  • Page D (Categorized as: Fruits)
  • Page E (Categorized as: Technology)

Then from functions.php, there would be some logics, like:

  • If Page is under Fruits Category, then echo "This is related to Fruits.";.
  • If Page is under Vehicles Category, then echo "This is related to Vehicles.";.
  • If Page is under Technology Category, then echo "This is related to Technologies.";.

I dont know this is about Taxonomy or Tagging or Custom Field or something. But:

  • What is the ideal way to do it please? (Especially to be able to control from backend coding.)

And again please let me repeat, "Pages". (Not about Posts or any other)

  • 1
    Use posts with categories and tags or custom post types with custom taxonomies, it is the best way of doing what you are describing. – cybmeta Jan 14 '15 at 10:55
  • Thank you but I think my question is about Pages. – 夏期劇場 Jan 14 '15 at 15:02
  • 1
    I know that your question is about pages, I just made a suggestion of data structure that can fit better the description of your issue. – cybmeta Jan 14 '15 at 15:46
  • 1
    @cybmeta I agree, if you need to categorize "pages" then you should create a Custom Post Type and Custom Taxonomy. The built-in Pages were not designed to have categories or be categorized. A Custom Post Type can be a page or a post or anything you want. Read More about Post Types. Another option is create a Parent Page called "Fruits" then make subpages, the parent page would act as a Category, though it truely isn't. – Howdy_McGee Jan 14 '15 at 18:02
0

You can use categories with pages by registering the category taxonomy for the page object type:

function categories_for_pages(){
    register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'categories_for_pages' );

If you want to use a separate taxonomy for this, you can register your own taxonomy for pages.

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.