Basic

Taxonomies

Introduction

Taxonomies are an important part of categorizing your site’s content, but the term often confuses beginners because “taxonomy” isn’t something most of us hear in daily life. In the simplest sense, Taxonomies are just a way to group related posts (or other pieces of content) together. That’s it! Though it’s a big word, it’s not as complicated as it sounds.

For example, if you have a blog about sports, you could create taxonomies for the different sports (football, basketball, cricket, etc.) and assign relevant posts to each taxonomy.

Taxonomies are helpful because they make it easier for readers to find related content (and also provide some context to your content, though that’s a secondary benefit).


Default Taxonomy Types

By default, VaahCms includes following types of Taxonomy:

  1. Countries
  2. Registrations
  3. Roles

Create Taxonomies and Taxonomy Types via VaahSeeder

User can create a taxonomies and taxonomy types through seeds. Create json files of name taxonomies.json and taxonomy_types.json at .../VaahCms/Modules/{module_name}>/Database/Seeds/json/ this directory.

taxonomies.json

[

    {
        "type_slug": "roles",
        "name": "Backend"
    },
    {
        "type_slug": "roles",
        "name": "Frontend"
    },
    {
        "type_slug": "registrations",
        "name": "Email Verification Pending"
    },
    .........
]

taxonomy_types.json

[

    {
        "name": "Countries"
    },

    {
        "name": "Cities",
        "parent_slug": "countries"
    },

    {
        "name": "Roles"
    },
    .........
]

To run these seeds, you have to add some code in DatabaseTableSeeder.php at .../VaahCms/Modules/{module_name}>/Database/Seeds/ this directory.

DatabaseTableSeeder.php

<?php
namespace VaahCms\Modules\<module_name>\Database\Seeds;


use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use WebReinvent\VaahCms\Libraries\VaahSeeder;

class DatabaseTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        VaahSeeder::taxonomyTypes(__DIR__.'/json/taxonomy_types.json');
        VaahSeeder::taxonomies(__DIR__.'/json/taxonomies.json');
    }

}

Create Taxonomy

Visit following url you will see the Taxonomy section:

<project-url>/backend#/vaah/manage/taxonomies/
taxonomy1

Now you have to create a Taxonomy by click on Create button. You will see a create page with following field.

taxonomy2

First field is Type and there option are in hierarchical format. You can also manage the taxonomy types by click on Manage Button. The PopUp will appear that contains Tree Viewof Taxonomy Types and has CRUD Operation.

taxonomy3

If you select any children type, you will see a new field of Parent name that has taxonomies of parent of choosen type.

Fill all Fields. Click on Save button.

taxonomy4

Now you can see the file in View Page.



Copyright © 2024