1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Categories 2.0

Discussion in 'Plugins' started by Nick, Aug 13, 2009.

  1. Nick

    Nick Well-Known Member

    Categories
    Version: 2.0
    Author: Nick Ramsay
    Created: 2009/07
    Last Updated:
    2013/05/31
    Tested on: Hotaru 1.4.0 - 1.5.0
    Plugins Required: None
    Plug & Play: Yes
    Supported: Yes

    Description
    Add categories to posts, urls and a drop-down, horizontal menu. Uses the Bookmarking, Submit and Widgets plugins.

    Instructions
    1. Upload the "categories" folder to your plugins folder.
    2. Install it from Plugin Management in Admin.

    Note: This plugin only supports one level of sub-categories

    Revision History
    v.2.0 2013/05/31 - shibuya246 - Add style choice and display ON/OFF switch to admin settings. Add new template
    v.1.9 2010/07/30 - Nick - Parent category tab gets active status when viewing sub category or post.
    v.1.8 2010/07/27 - Nick - Fix for url friendly post pages breaking with non-alphanumeric category safe names.
    v.1.7 2010/06/07 - Nick - Applied html entities to ampersands in posts, i.e. "posted in Food & Drink"
    v.1.6 2010/05/22 - Nick - Fix for home page title tags and moved Category RSS from SB Base into this plugin
    v.1.5 2010/04/14 - Nick - Top stories page name changed from "index" to "popular"
    v.1.4 2010/03/24 - Nick - Added an "active_cat" class to the category bar for the current category
    v.1.3 2010/02/20 - Nick - Meta description and keywords taken from Category Manager
    v.1.2 2009/12/28 - Nick - Updated for compatibility with Hotaru 1.0
    v.1.1 2009/11/30 - Nick - Categories before post title in breadcrumbs, plugin hooks in the category bar, and various big fixes
    v.1.0 2009/11/27 - Nick - Added clickable parent category to category breadcrumbs
    v.0.9 2009/11/04 - Nick - Updated install function for easier upgrading
    v.0.8 2009/10/18 - Nick - Bug fix for lost settings when Submit reactivated
    v.0.7 2009/10/15 - Nick - Bug fixes for slashed apostrophes
    v.0.6 2009/10/13 - Nick - CSS and template update
    v.0.5 2009/10/08 - Nick - Updates for compatibility with Hotaru 0.7
    v.0.4 2009/10/01 - Nick - Updates for compatibility with Hotaru 0.6
    v.0.3 2009/08/28 - Nick - Updates for compatibility with Hotaru 0.5
    v.0.2 2009/08/19 - Nick - Added optional drop-down menu bar
    v.0.1 2009/08/13 - Nick - Released first version

    Please click "Rate Thread" and give this plugin a rating. Thank you.

     

    Attached Files:

    Last edited by a moderator: Feb 6, 2010
  2. mabujo

    mabujo Designer

    Nick,
    One thing I noticed about the categories plugin is that it would be great if the <li> for the current category had an identifying class.
    With the sort box for example, if the user is viewing the upcoming page, the <li> for that tag has class="active".
    It would be great for making templates if the user is viewing say the 'world news' category, that <li> would have class="active".

    I couldn't see a way to do it with templates as the category_bar template is pretty much just this wrapped in an unordered list :

    Code:
    <?php $h->pluginHook('category_bar_start'); ?>
    
    <?php echo $h->vars['output']; ?>
    
    <?php $h->pluginHook('category_bar_end'); ?>
     
  3. Nick

    Nick Well-Known Member

    mabujo,

    Change the categoryLink function in categories/categories.php from this:

    PHP:
        /** 
         * HTML link for each category 
         * 
         * @param array $category  
         * @param string $output  
         * @return string $output 
         */ 
        
    public function categoryLink($h$category$output
        { 
            if (
    FRIENDLY_URLS == "true") {  
                
    $link $category->category_safe_name;  
            } else { 
                
    $link $category->category_id
            } 
        
            
    $category stripslashes(html_entity_decode(urldecode($category->category_name), ENT_QUOTES,'UTF-8'));
            
    $output .= '<li><a href="' $h->url(array('category'=>$link)) .'">' $category "</a>\n";
            
            return 
    $output
        }
    to this:

    PHP:
        /** 
         * HTML link for each category 
         * 
         * @param array $category  
         * @param string $output  
         * @return string $output 
         */ 
        
    public function categoryLink($h$category$output
        { 
            if (
    FRIENDLY_URLS == "true") {  
                
    $link $category->category_safe_name;  
            } else { 
                
    $link $category->category_id
            }
            
            
    $active '';
            if (isset(
    $h->vars['category_id']) && ($h->vars['category_id'] == $category->category_id)) {
                
    $active " class='active_cat'";
            }
            
            
    $category stripslashes(html_entity_decode(urldecode($category->category_name), ENT_QUOTES,'UTF-8'));
            
    $output .= '<li' $active '><a href="' $h->url(array('category'=>$link)) .'">' $category "</a>\n";
            
            return 
    $output
        }
    Give that a try and if you're happy with it, I'll upgrade the plugin with those changes.
     
    mabujo likes this.
  4. mabujo

    mabujo Designer

    Nick,

    Good job, that was exactly what I was talking about. I tested it and it works - Thanks! :)
     
  5. Gunaxin

    Gunaxin Well-Known Member

    Figured I'd toss out my suggestion on Categories as well. I actually decided not to use sub-categories, with the main reason being ease of submission. If you use sub-categories, they all appear in the categories drop down menu (I forget how they are sorted, maybe alphabetical?) which can make that menu long and confusing. I thought that made the submission process too difficult, as I was planning on adding about 30 sub-categories to the existing 6 main categories that I had.

    A solution to fix this issue (that I may work on eventually myself, if I find the time) would be maybe to do some form of check boxes. That way the categories are displayed on screen, maybe visually arranged under their sub-categories, and sorted properly. This would also potentially allow a post to be listed in multiple categories which would be beneficial as well.

    Just something floating around in my head, that I figured I'd toss out to the masses.
     
  6. Nick

    Nick Well-Known Member

    Updated: v.1.4 2010/03/24 - Nick - Added an "active_cat" class to the category bar for the current category (no template or css changes necessary).
     
  7. Nick

    Nick Well-Known Member

    Updated: v.1.5 2010/04/14 - Nick - Top stories page name changed from "index" to "popular" (Hotaru 1.2)
     
  8. xhotaru

    xhotaru New Member

    Link clicking error

    Clicking on a post link doesn't redirect to external website but instead there is the following error:

    Code:
    Notice: Undefined index: category_parent in /home/***/public_html/directory/content/plugins/categories/categories.php on line 233
    I have checked line 233 and it is:

    Code:
     $parent_id = $h->vars['category_parent'];
    I only have a single parent category and it worked fine for a few posts but now this bug appeared. Please help!
     
  9. Gunaxin

    Gunaxin Well-Known Member

    Removed, cuz I just realized I suggested the same feature back in March, lol

    I'll just add to that previous suggestion that possibly an easy way to fix the confusing drop down list would be to tab over the sub categories in the list, and have them listed in a hierarchy. Would that just be a CSS change?
     
    Last edited: Aug 31, 2010
  10. Nick

    Nick Well-Known Member

    Possibly because you installed the deprecated SB Base plugin as per this post?
     
  11. Nick

    Nick Well-Known Member

    Not really, the pull-down menu shows a tree with child categories indented under their parents. I'm not sure why that would be confusing. The multiple checkbox idea wouldn't work because posts can only go in one category. Allowing them in multiple categories would require database changes, edits to database queries across multiple (dozens?) of plugins and redesigning how Hotaru handles urls. No small task at all.
     
  12. Gunaxin

    Gunaxin Well-Known Member

    Ah, last time I tried, the tree thing wasn't there I don't think. If that is implemented now, I can probably add subcategories. I assume something submitted to a subcategory would show up on the main category page correct?
     
  13. Nick

    Nick Well-Known Member

    Right, can't remember when, but the indents were added much later. Yes, sub-category posts show up on their parent category page. Don't forget you can only have one-level of child categories, though.
     
  14. xhotaru

    xhotaru New Member

    You are right, removed it and it's fine now.

    PS
    Please reply to me in the other thread.
     
  15. Fireteo

    Fireteo New Member

    Is there a plugin that can make the same sub-categories for different main cateogries? Or can you make it to do that. It will be great if the sub categories instead of being drop-down menu to appear horizzontaly and static when a main category is open(maybe smaller boxes to easy see the difference between the main and sub).
     
  16. Nick

    Nick Well-Known Member

    No, I'm afraid category names must be unique.
     
  17. angolanmade

    angolanmade Well-Known Member

    I have created two different main categories - example - NCAA and CAAA under each of these categories I would like to create sub-categories such MEN and WOMEN.
    However this doesnt work since hotaru already recognizes the previously created Men and Women sub-categories under the first parent category.

    Any input on this?

    Thanks
     
  18. Nick

    Nick Well-Known Member

    Category names must be unique, regardless of whether they are parent or child categories.
     
  19. done

    done New Member

    Wow, I really need two layers of subcategories and designed my site around that, but just realized it only works with one. Any suggestion on how to program that in?

    Update: my fix for categories displaying (though unique to my cat counts)

    PHP:
    if ($parent <= && $parent>=2) {
                    
    $children $h->getCatChildren($h->vars['category_id']);
                    if (
    $children) {
                        foreach (
    $children as $child_id) {
                            
    $filter_string .= ' || post_category = %d';
                            
    array_push($values$child_id->category_id);
                        }
                    }
                }
                else if ( 
    $parent == 1) {
                    echo 
    "accept";
                    
    $children $h->getCatChildren($h->vars['category_id']);
                    
    print_r($children);
                    if (
    $children) {
                        foreach (
    $children as $child_id) {
                            
    $filter_string .= ' || post_category = %d';
                            
    array_push($values$child_id->category_id);
                            
                            
    $subchildren$h->getCatChildren($child_id->category_id);
                            if (
    $subchildren) {
                                foreach (
    $subchildren as $subchild_id) {
                                    
    $filter_string .= ' || post_category = %d';
                                    
    array_push($values$subchild_id->category_id);
                                }
                            }
                        }
                    }
                }
     
    Last edited: Dec 29, 2010
  20. lwest300

    lwest300 New Member

    I posted that their was a bug in the category listing because I have 2 child sub categories and now I read that the plugin only supports 1 child sub.

    Will you ever offer support for more than 1 child?
     

Share This Page