WordPress.org

Forums

Category Meta plugin
[resolved] How do you make an image also a link?? (3 posts)

  1. paa1605
    Member
    Posted 4 years ago #

    Hey guys,

    im currently using this plug-in to give categories an associated image. Does anyone know how to make this image a link to the associated category?? For example, i have a category called Nike, and the image is the logo. On the nike child category pages i would like to use this image in the sidebar to allow users to click it and be linked back to the main nike page.

    If anyone knows how to do this i would be extremely grateful. Thanks.

    Here is the code im using which currently displays the image, but not as a link. It was adapted from another form post about this particular plug-in.

    <?php
    if(function_exists('get_terms_meta')) {
    $screen = get_terms_meta($thisCat, 'logo');
    $screen = $screen[0];
    } ?>

    <img src="<?php echo ($screen); ?>" />

  2. stevecoy
    Member
    Posted 4 years ago #

    There are many ways to get the link of a category, depending on whether you're in the Loop or not. It sounds like in your case you want to do this:

    <?php
    //get ID of current child category, this only works when is_category() is true (you're on a category page)
    $current = get_query_var('cat');
    //get all the data for the current category
    $cat = get_category($current);
    $parent = $cat->category_parent;
    ?>

    Then wrap your image in a link:

    <a href="echo get_category_link( $parent)"><img src="<?php echo ($screen); ?>" /></a>

    Try these pages for documentation depending on how you're trying to reference the category ID:
    http://codex.wordpress.org/Function_Reference/get_category_parents
    http://codex.wordpress.org/Function_Reference/get_the_category

  3. paa1605
    Member
    Posted 4 years ago #

    Thanks for your help. I managed to get it working! For anyone that might have a similar problem i used the following code...

    <?php
    $current = get_query_var('cat');
    $cat = get_category($current);
    $parent = $cat->category_parent;
    if(function_exists('get_terms_meta')) {
    $screen = get_terms_meta($parent, 'logo');
    $screen = $screen[0];
    } ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Category Meta plugin
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic