HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Ad-on request for Category URL - naming convention.

I thought it would be a neat idea if an add-on could be made that would incorporate the parent category name in the www.example.com/categories/ path when creating subsequent (child) categories.

For example:

When creating a root category named: test and then adding the adding a child (sub) category named: baseball

the category url would automatically show as follows:

www.example.com/categories/test-baseball.

If a sub category were added to baseball, named football then the category url wold look as follows:

www.example.com/categories/test-baseball-football


This automation would be very welcomed in situations, where many forums have to be hand inputted.

To take it one step further, perhaps a unique database identifier could be added to prevent 100% occurrence of creating a duplicate url - although that might impact SEO friendly url protocol?

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You can edit the url of a category. So changing the it to category/root-parent-children can be done from the admin section.

    Since setting up categories is a one time process, wiring a plugin just for changing the url would be kind of overkill.

  • Options

    Hi RJ,

    It's not efficient when when creating many categories, especially nested - it would be a nice convention - parent nodes are linked to subsequent child nodes on the back end, so it would make sense to follow the schema and automate the process using the name of the parent node and linking with the name of the child node with respect to the url category property. When creating a parent node, the name you call the category is automatically inserted in the url category property, so when then, wouldn't you carry over the name of the parent category when creating a sub category with respect the the url category property.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    My personal opinion is that a multitude of categories is negative for evolving a big community. New users feel lost, sometimes it will be hard to find the correct forum for your needs, some forums will look orphaned, etc.

    I would always strive for some general forums and then use tags if I feel the need to let users further specify something.


    But that doesn't help you any further... ;-)


    So to deal with your problem I'd say there are some approaches.

    Having a plugin which alters the url when the category is created is not what I think would be best. It is very easy to re-arrange categories and that's because this is a feature many people use. So if the url of the category is based on the structure it had when it was created, the slug will be wrong when categories are re-arranged and the slug can easily be forgotten.

    You could build a more or less complex sql query which can be run to rename the url of a category.

    You can export your categories to Excel and with a number of vlookups get the desired slug, change it and re-import that.


    (Before you try any of the SQLs below, back up your GDN_Category table!!!)

    This is a SQL to change the slug of all categories nested 5 levels deep:

    UPDATE GDN_Category c,
    (
    SELECT c5.CategoryID, CONCAT(c1.UrlCode, "-", c2.UrlCode, "-", c3.UrlCode, "-", c4.UrlCode, "-", c5.UrlCode) AS NewUrlCode
    FROM GDN_Category c1
    LEFT JOIN GDN_Category c2 ON c2.ParentCategoryID = c1.CategoryID
    LEFT JOIN GDN_Category c3 ON c3.ParentCategoryID = c2.CategoryID
    LEFT JOIN GDN_Category c4 ON c4.ParentCategoryID = c3.CategoryID
    LEFT JOIN GDN_Category c5 ON c5.ParentCategoryID = c4.CategoryID
    WHERE c5.Depth = 5
    ) AS t
    
    SET c.UrlCode = t.NewUrlCode
    WHERE c.CategoryID = t.CategoryID
    


    You need to change it and let it run multiple times to get all categories:

    UPDATE GDN_Category c,
    (
    SELECT c3.CategoryID, CONCAT(c1.UrlCode, "-", c2.UrlCode, "-", c3.UrlCode) AS NewUrlCode
    FROM GDN_Category c1
    LEFT JOIN GDN_Category c2 ON c2.ParentCategoryID = c1.CategoryID
    LEFT JOIN GDN_Category c3 ON c3.ParentCategoryID = c2.CategoryID
    WHERE c3.Depth = 3
    ) AS t
    
    SET c.UrlCode = t.NewUrlCode
    WHERE c.CategoryID = t.CategoryID
    


  • Options
    selfawareselfaware New
    edited May 2020

    Thanks for the reply, I really appreciate it.

    I'm just being extra lazy, because it would be when populating the url category, to have the parent name carried over when creating the sub category, so I don't have to manually enter it each time and remember the name of the parent category.

    On a side note:

    If I need some custom coding work to inject forums, via the api, via a flat file is that something you would be able to do for a fee and if

    not, if you could pass along some folks that would, here or via PM that would be great

Sign In or Register to comment.