Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-05-05 10:10:29

astick360
Member
Registered: 2022-05-05
Posts: 16

loading section assigned to article attached to category

[ SPLIT OFF OF THE TOPIC CUSTOM SORTING/ORDER BY CATEGORY ]

Hello and greetings to everyone. I will join the discussion because I have a problem with the category menu. Can I assign any section for a given category using the category menu?

So that always choosing, for example, menu items: category 2 CMS knew what section he should use, i.e. assigned the appropriate page and styles CSS.

Offline

#2 2022-05-05 10:40:11

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: loading section assigned to article attached to category

Categories are Section agnostic so there’s no direct way to tie them together without some code. It really depends what you’re intending to do (e.g. display a menu or a list or individual articles or when creating an article from the admin panel).

What you could do, for example, is check the article category, look up which section it is in, and get the page and style that way.

As I say, depends what your use case is.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2022-05-05 11:43:24

astick360
Member
Registered: 2022-05-05
Posts: 16

Re: loading section assigned to article attached to category

At the moment I do not know how to exalt directly outside the section of her code (page). Entering the article directly, this connection with the section occurs. However, when displaying a single article in the page code category is the default. How can I call a page code from the category level by assigning an article with a section to it.

Offline

#4 2022-05-06 17:00:59

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: loading section assigned to article attached to category

Hi, astick360, and welcome to the forum.

astick360 wrote #333203:

Can I assign any section for a given category using the category menu?

So that always choosing, for example, menu items: category 2 CMS knew what section he should use, i.e. assigned the appropriate page and styles CSS.

Reminds me of something we’ve had in the German forum section (back in 2013, when we had one). It was solved by Javascript which I’m too rusty in to assist, sadly. Plus: I can’t tell whether this would work exactly in the situation you have. Nevertheless worth trying. You’d need the plugin bot_write_tab_customize that offers a form field to contain and inject your Javascript into the Write page.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2022-05-06 17:03:56

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: loading section assigned to article attached to category

astick360, please provide a catchy title for your question and I’ll open a separate topic for you with only your posts for better visibility.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2022-05-06 20:43:24

astick360
Member
Registered: 2022-05-05
Posts: 16

Re: loading section assigned to article attached to category

uli wrote #333207:

astick360, please provide a catchy title for your question and I’ll open a separate topic for you with only your posts for better visibility.

Title: Selection of menu category and loading the section assigned to the article attached to this category.

Offline

#7 2022-05-07 22:08:31

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: loading section assigned to article attached to category

Sorry, astick360, I’ve had to shorten the title, the forum software defines “catchy” as 70 characters max. Best of luck!

BTW: Did you perceive my proposal some posts above?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2022-05-08 05:18:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: loading section assigned to article attached to category

I remember we used to have a javascript based plugin that could limit the category choices on. a per section basis. I cannot think of how it can. be the other way round.

Having said that, the later versions of txp can create urls based on section/cat1/cat2/title. What you are asking may limit the possibilities of this functionality.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#9 2022-05-08 08:42:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: loading section assigned to article attached to category

uli wrote #333206:

Reminds me of something we’ve had in the German forum section …

colak wrote #333211:

I remember we used to have a javascript based plugin that could limit the category choices on a per section basis.

Good thinking! Some searching through past forum articles turned up these:

Those both work around the other way, i.e. choosing a section sets the category but the second article gives you the code structure you need to do the reverse (thanks to “The Blue Dragon”).

Turning that code around to make the Category 2 dropdown switch the section dropdown would give you the following jQuery:

$(function(){    
    $('#category-2').change(function(){
        var selectedCategory = $(this).val(), defaultSection;
// Define the sections to choose for each category
        switch(selectedCategory){
            case 'news': defaultSection = 'your_section_name1'; break;
            case 'blog': defaultSection = 'your_section_name2'; break;
            case 'videos': defaultSection = 'your_section_name3'; break;
        }
// Set the section dropdown to defaultSection and trigger a change event
        if(defaultSection){
            $('#section').val(defaultSection);
            $('#section').change();
        }
    }).change();
});

replacing news, blog and videos and the your_section_name1 in the case statements to match your case. Important: use the section and category names, not the titles. The above code allows you to assign section names that are different to your categories.

If you have already exactly matched your section names with your category names, there’s no need for the switch block in that code and you can go straight to:

$(function(){    
    $('#category-2').change(function(){
        var selectedCategory = $(this).val();
         $('#section').val(selectedCategory);
         $('#section').change();
    });
});

This shorter version does not verify if a matching section exists, so you must make sure in advance that you have a matching section name for each selectable category name. The code above requires manual editing but is more robust as it ignores values that don’t exist.

To add this custom jQuery javascript to the admin area you can either:

  • paste one of the above scripts into the textarea of the plugin bot_wtc, or
  • use the built-in facility of the admin theme and save the script to a file called custom.js in the ‘hive’ admin theme (or whatever admin theme you’re using), e.g. /textpattern/admin-themes/hive/assets/js/custom.js. See the readme for the admin theme.

TXP Builders – finely-crafted code, design and txp

Offline

#10 2022-05-08 17:04:42

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: loading section assigned to article attached to category

jakob wrote #333212:

  • use the built-in facility of the admin theme and add your own custom.js file

Completely forgotten. Thanks for the brush-up!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB