Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-06-18 14:04:45

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 327
Website

Default Category by Section

I use plugin rah_default_category to set a default category, but that sets a default category site wide (any section selected gets the same default category).

On a site with many sections and categories, a default category based on section would be most useful.

Is there a way?

Offline

#2 2016-09-03 11:48:26

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 605
Website

Re: Default Category by Section

You can use Javascript for that (including jQuery),
find your favorite why to insert Javascript into TXP write-tab (after jQuery)
and then use this code, and change the sections names and your desired category name
for this code you must use names, not titles:

$(function(){    
    $('#section').change(function(){
        var section = $(this).val(),
        defaultCategory1;
// Creating a switch statement
        switch(section){
            case 'news': defaultCategory1 = 'your_category_name1'; break;
            case 'blog': defaultCategory1 = 'your_category_name2'; break;
            case 'videos': defaultCategory1 = 'your_category_name3'; break;
        }
// Select the category from Category-1 and trigger a change event
        if(defaultCategory1){
            $('#category-1').val(defaultCategory1);
            $('#category-1').change();
        }
    }).change();
});

Offline

Board footer

Powered by FluxBB