I added support for category images to directory plugin, here is the code

I wanted category images in grid view so i found a category image plugin that would work and added the code to display them. I used the plugin:

categories image
here: http://wordpress.org/plugins/categories-images/

then edited: directory/core/template-tags.php and add on line 95 this:

if (function_exists('z_taxonomy_image_url')) {
		$output .= '<center><a href="' . get_term_link( $category ) . '" title="' . __( 'View all contractors in ', DR_TEXT_DOMAIN ) . $category->name . '" ><img src="' . z_taxonomy_image_url($category->term_id) . '" /></a></center>';
		}

Any chance of getting this merged? I hate running a hacked plugin.

I also had to edit style-directory.css line 321 and change it from: padding: .2em 1em;
to:
text-align: center;

to get the titles to center well.

Let me know what you guys think

  • PC
    • WPMU DEV Initiate

    Hey there,

    Greetings and thanks for your post.

    You don't need to hack the plugin in order to get that working.

    Here is what you need to do :

    Install : http://wordpress.org/plugins/add-actions-and-filters/

    Add your code to that plugin settings instead of editing the directory core file

    For adding the CSS, you can use something like : http://wordpress.org/plugins/imporved-simpler-css/ and that would allow you to add CSS without core modification of the stylesheet file.

    I have however sent a note to Arnold for his feedback on the same :slight_smile:

    Cheers, PC

  • PC
    • WPMU DEV Initiate

    Hey there,

    Sorry for missing it.

    When you install the plugin I suggested above, you can use it to add any code which would avoid you modifying the core plugin so that your code changes are future proof.

    So you install that plugin, go to the editor and add the below code :

    if (function_exists('z_taxonomy_image_url')) {
    		$output .= '<center><a href="' . get_term_link( $category ) . '" title="' . __( 'View all contractors in ', DR_TEXT_DOMAIN ) . $category->name . '" ><img src="' . z_taxonomy_image_url($category->term_id) . '" /></a></center>';
    		}

    Let me know if you are not able to figure it out and I will have a closer look.

    Cheers, PC

  • mcmasterp
    • The Incredible Code Injector

    thanks for getting back to me.

    I did as you said but it doesn't make the cat images show. The function is good but it doesn't hook in and insert the code. What do I need t add to tell it to place that code in the output where I want it?

  • PC
    • WPMU DEV Initiate

    Hey there,

    Strange, it worked for me on my lab site.

    Did you undo the core changes before trying it out ? If yes, then I will need to have a closer look at your site with more details.

    Can you please send me your login details via our secure contact form

    1: Mark the email to my attention

    Attn: PC

    2: Include a link of this thread in the email

    3: Include FTP and WordPress super admin details.

    4: While filling the form, select "I have a different question" from the list.

    Looking forward for a response on this.

    Cheers, PC

  • PC
    • WPMU DEV Initiate

    Hey there,

    Thanks for writing back on the email.

    My bad, I did not realize that we not only need to add images but also display them on the frontend.

    Let me ask @Arnold if there are any plans to add it to a future plugin release :slight_smile:

    Cheers, PC

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.