• Resolved jaseemts

    (@cooljaz124)


    Hi,

    Does anyone know how to add custom meta field in Categories ? Like, When I make a new category, there should be 2 additional fields

    – Icon , where we add url of icon image of that category.
    – Check Box to set that particular category “POPULAR”

    See the screenshot of the functionality I have asked help for.

    Thanks in advance.
    Jaz

Viewing 15 replies - 1 through 15 (of 25 total)
  • Joseph

    (@jpe24524)

    I think you’ll need to create a new table. Custom fields are for posts only.

    Thread Starter jaseemts

    (@cooljaz124)

    Thanks Joseph, yes it will be playing with tables. Any more specific solutions with codes ?

    Functionality achieved from this plugin is what I am looking for. But, this plugin just have text,text-area and image as the additional meta fields. I need check box as well and a way to fetch the meta values in the loop.

    Thanks.
    Jaz

    Joseph

    (@jpe24524)

    You can hack that plugin to include checkbox.

    Find the following in /views/options.php

    <option value="text"><?php _e('Text','wp-category-meta'); ?></option>
    <option value="textarea"><?php _e('Text Area','wp-category-meta'); ?></option>
    <option value="image"><?php _e('Image','wp-category-meta'); ?></option>

    and add

    <option value="checkbox"><?php _e('Check Box','wp-category-meta'); ?></option>

    Insert the following after line 578 in wp-category-meta.php

    <?php } elseif($inputType == 'checkbox') { ?>
    <tr>
    	<th scope="row" valign="top"><label for="category_nicename"><?php echo $inputName;?></label></th>
    </tr>
    <tr>
    	<td><input value="checked" type="checkbox" <?php echo $inputValue ? 'checked="checked" ' : ''; ?>
    		name="<?php echo 'wptm_'.$inputName;?>" /><br />
    		<?php _e('This additionnal data is attached to the current term', 'wp-category-meta');?></td>
    </tr>

    The checked category will have a meta_value of “checked”

    jocken

    (@jocken)

    Big thanks! This was exactly what I have been looking for!

    Thread Starter jaseemts

    (@cooljaz124)

    Thanks a lot Joseph.

    @joseph @jocken But, is the plugin working in WordPress 3.0.1 ?? I can’t see it working in 3.0.1, any lucks for you guys ?

    Joseph

    (@jpe24524)

    I’ve tested it on 3.0.1 and it works. However, there is one minor problem with the plugin itself. The list doesn’t refresh automatically when a new category is created. Everything else seems fine.

    Thread Starter jaseemts

    (@cooljaz124)

    Oh ! Can you copy here the function you used to display the meta info here ?? Is it the same that as they described in the plugin page ? I’m having some hard luck !

    Joseph

    (@jpe24524)

    Yep, I used get_terms_meta and get_all_terms_meta.

    Note that the functions return a numeric and 2D array respectively.

    Thread Starter jaseemts

    (@cooljaz124)

    Thanks I will try it again.

    The thing is I need to fetch all categories, style certain category a bit different. So I’m trying to put the “certain” categories with a meta value so tht I can style them differently. Can you help getting me the right code ?

    Joseph

    (@jpe24524)

    Just to clarify before I help you with the code. You want a list of all categories and have different styling for ones with the popular meta?

    Thread Starter jaseemts

    (@cooljaz124)

    Exactly !

    I need to be able to change the popular categories often. Thats why thought of this plugin. Thanks for your help, Joseph.

    Joseph

    (@jpe24524)

    A couple of things I forgot to ask. It was my sleeping time ??

    How are you planning to style it differently?
    If it’s only different in between the anchor tags then we could just use a filter to change the output of wp_list_categories.

    If the filter is not enough, do you want it flat or multilevel?
    If it’s flat then we just need to run a simple loop. If it’s miltilevel, we’ll need to extend the WordPress walker class.

    Thread Starter jaseemts

    (@cooljaz124)

    Hi,

    The markup goes like this

    <span class="category-name popular">Category Name
         <div class="left"></div><!-- *left round corner -->
         <div class="right"></div><!-- *right round corner -->
     </span>

    <span> have to get an additional class “popular”, its not ??

    * Some dumb IE compatibility, can’t help ??

    Joseph

    (@jpe24524)

    I made a mistake about the filter. It also filters the title and alt attributes so it’s no good.

    Are you already using a custom function to add the markup? If so I’ll just modify that to include the popular class.

    Thread Starter jaseemts

    (@cooljaz124)

    Mistake ? Is it about the hack on plugin to add the checkbox ? Oops.

    Nop, I have’nt added any custom functions.

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘How to add Meta-Field in Categories ?’ is closed to new replies.