Creating Categories Programmatically

Managing categories in Publishing can be done multiple ways; from destination groups to bulk creation – but the most powerful way is with the Page Configuration Variable [category=*]

Like all other PCV we add this in the article content. Unlike other PCV, we can only utilise the variable when creating the campaign.

Examples & How to Use

Basic Example

Let's say we have 2 pieces of content that we want to categorise differently:

<h1>Dog Food: The Best Brands This Year</h1> ... about dog food ... [category=Dog Food]
Click to copy
<h1>Dog Toys Ranked – Our Picks</h1> ... about dog toys ... [category=Dog Toys]
Click to copy

Usually we would have to create two destination groups to accomplish this, but now we can assign the category straight from the content.

Creating Nested Categories

Nested Categories can be created by adding a "/" between the titles. The category Dogs/Dog Toys will create the Dog Toys category below the Dogs category. We can leverage this when creating programmatic categories, too:

<h1>Dog Food: The Best Brands This Year</h1> ... about dog food ... [category=Dogs/Dog Food]
Click to copy
<h1>Dog Toys Ranked – Our Picks</h1> ... about dog toys ... [category=Dogs/Dog Toys]
Click to copy

Combined with the Category/Post structure, we can create great URLs:

  • pet-store.example.com/dogs/dog-food/dog-food-the-best-brands-this-year
  • pet-store.example.com/dogs/dog-toys/dog-toys-ranked-our-picks

Combining with Variables & MPSS

We can also leverage any variables or MPSS too. We could abstract the "Dog" part of our articles to multiple pet types, for example:

[@=pet]{Dog|Cat}[/pet] [@=type]{Food|Toys}[/type] <h1>[@pet] [@type]{: The Best Brands This Year| Ranked – Our Picks}</h1> ... about dog/cat food/toys ... [category=[@pet]s/[@pet] [@type]]
Click to copy

...will create:

<h1>Cat Toys: The Best Brands This Year</h1> ... [category=Cats/Cat Toys]
Click to copy
<h1>Dog Food Ranked – Our Picks</h1> ... [category=Dogs/Dog Food]
Click to copy
<h1>Dog Toys: The Best Brands This Year</h1> ... [category=Dogs/Dog Toys]
Click to copy

...and more combinations of course!