Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Assign a category to a parent on creation
Hi, I will like to know please how to assign a category to a parent category on creation in the Categories tab?
For example just like in the smd_write_cats
plugin
(From the plugin help page:)
If you wish to assign your new category beneath an existing category you can specify an alternative syntax:
Parent category -> New category
Offline
Re: Assign a category to a parent on creation
It’s an extra step after creation. You have to edit the category to set the parent.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#3 2012-03-30 23:32:05
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,305
Re: Assign a category to a parent on creation
THE BLUE DRAGON wrote:
assign a category to a parent category on creation in the Categories tab
Hi Gil, there’s one plugin I know of that works on the Categories tab but it functions a little different from what you’d expect: via spreadsheet/tabular data. It comes with a big plus, though: You can create multiple categories at once and for all of TXP’s category sorts. Have a look at dzd_multicat_creator.
PS: Still dreaming of the days when you can checkmark an existing category and then from the “With selected …” dropdown menu choose the new entry “Create child category”.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Assign a category to a parent on creation
uli wrote:
Still dreaming of the days when you can checkmark an existing category and then from the “With selected …” dropdown menu choose the new entry “Create child category”.
I’ve tried that before and hit a brick wall due to the way the With selected thing is coded. It’s probably doable if I put my mind to it though.
In the meantime, however, I think I’ve figured out a way to assign a parent at cat creation time. No promises yet, but I think it’ll work. Watch this space.
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
Re: Assign a category to a parent on creation
Thanks Matt and Stef, Uli thanks I am going to take a look at that plugin :)
In the meantime I came up with a JS workaround,
for the site I’m working on I want the client to always assign a new article category to a specific parent,
so what I did was:
A small change to the txp_category.php
(sorry) at line #342
from:
, ' class="'.(($ctr%2 == 0) ? 'even' : 'odd').' level-'.$level.'"');
to:
, ' class="'.(($ctr%2 == 0) ? 'even' : 'odd').' level-'.$level.' '.$name.'"');
Which adds the name of the category to it’s paragraph class name.
Then using JS to make the workaround:
Just a function that I found in the net that gets the url vars.
function GetURLVar(varName) {
var urlHalves = String(document.location).split('?');
var urlVarValue = '';
if (urlHalves[1]) {
var urlVars = urlHalves[1].split('&');
for (i = 0; i <= (urlVars.length); i++) {
if (urlVars[i]) {
var urlVarPair = urlVars[i].split('=');
if (urlVarPair[0] && (urlVarPair[0] == varName)) {
urlVarValue = urlVarPair[1];
}
}
}
}
return urlVarValue;
}
Check if the message as a ‘success’ class and grabs the new category-name from it ‘strong’ tag
then look if that category exist in the page since deleting a category also return a ‘success’ class.
If the category exist then get it’s edit link and redirect to it with a url var name ‘newc’
function newProductCategory(){
if($('#message').hasClass('success')){
var cname = $('#message.success strong').html();
if($('p.level-0.'+cname).length > 0){
var edit_link = $('p.level-0.'+cname+' a').attr('href');
window.location.href = edit_link+'&newc='+cname;
}
}
}
On document ready checks if we are in the Categories tab,
Then do that newProductCategory()
mentioned above.
checks if the url var ‘newc’ exist, if it is then select the specific parent category which in this case it’s ‘products’
and then just submit the form which sends back to the ‘Categories’ tab main list.
$(document).ready(function(){
if($('#page-category').length > 0){
setTimeout('newProductCategory()',1000);
var ncategory_name = GetURLVar('newc');
if(ncategory_name.length > 0){
$('#category_container.txp-edit select.list[name="parent"]').val('products');
$('#category_container form.edit-form').submit();
}
}
});
That’s it, not pretty and it is weird, but that’s my workaround as a none PHP developer.
BTW: I do use smd_write_cats
in the Write-tab but I also want it in the Categories-tab.
For smd_write_cats
I also use JS:
$('#page-article .publish').click(function(){
if ($('#section').val() == 'products'){
var new_category = $('#smd_writecat').val();
$('#smd_writecat').val('products -> '+new_category);
}
});
Please don’t kill me LOL :P
Offline
#6 2012-03-31 12:50:28
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,305
Re: Assign a category to a parent on creation
Bloke wrote:
In the meantime, however, I think I’ve figured out a way to assign a parent at cat creation time.
Cool! I’m open to anything that takes some clicking off us.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Assign a category to a parent on creation
uli wrote:
I’m open to anything that takes some clicking off us.
Et voila. Thank you both for testing.
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