• Hi Eric,

    I have just found and downloaded your WP Category Meta plugin. Looks just what I need. Thank you.

    However due to my lack of experience with coding I do not know where I should put the code snippet to retrieve the meta?

    if (function_exists('get_all_terms_meta')) { $metaList = get_all_terms_meta($category_id); }

    Would you please which WP file and where in that file I should put the code?

    Regards,

    Ray Atreides

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author elebail

    (@elebail)

    Hello,

    The location to put the code depends on what you want to do.
    Usualy those bit of code are included into your WordPress Theme.

    I won’t explain how to create a theme here, there are already a lot of articles on that subject.
    ex : http://codex.wordpress.org/Theme_Development

    The functions are avalaible to all the theme templates so you can use it in every part of your theme (when the plugin is activated of course).

    May-be you can tell me what you want to do, I can write an answer more usefull to you.

    Regards,
    Eric Le Bail

    Thread Starter ratreides

    (@ratreides)

    Hi Eric,

    Many thanks you for your reply.

    After reading your response it may be that I do not understand the plugin and its functionality and correct use?

    I wish to add a meta description to all of my Categories & Category Posts for SEO purposes. I cannot find a way to do this within WordPress or my Theme (Frugal).

    I got the impression that your plugin would allow me to do this?

    Please let me know if I have misunderstood the proposed functionality of your plugin?

    If not and I am on the right track, all I need is for the meta description to be inserted into Category Pages and Category Posts just like they are in Pages, but do not know how to achieve that.

    Many thanks for your time.

    Regards,

    Ray

    Plugin Author elebail

    (@elebail)

    Hello,

    Ok, I see what you want to do.

    Yes my plugin alow you to do it.
    1) use the administration interface to set-up a meta called ‘my_description’ for example.
    2) in the category administration page you’ll see the ‘my_description’ field and you can fill it for all your categories.

    3) Now you need to customise your theme to display the meta.
    The theme files are usualy in the folder:
    wordpress/wp-content/themes/<your_theme_name>

    Usualy the template for category pages is in a file called “category.php”
    In this file, add the code like (will display the value of your meta):

    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $category_id = $cat->term_id;
    
    if (function_exists('get_terms_meta')) {
        $my_decription_value = get_terms_meta($category_id, 'my_description');
        echo $my_decription_value;
    }

    Of course this is a sample, you can adapt this code to your needs.

    Regards,
    Eric

    Thread Starter ratreides

    (@ratreides)

    Hi Eric,

    Many thanks for your response.

    I followed your instructions, added a meta for Categories and added some data for the meta.

    I used your example meta ‘my_description’ and added this meta data “test meta description HERE IT IS” for simplicities sake.

    I then placed your code into my archive.php page (that is what the Category page is named in my theme).

    However I am not EXACTLY sure where to place your block of code within the archive.php page?

    I have tried a number of different places but I am not getting the result that I require?

    Am I required to enter a Category ID or slug into the code?

    Just to be sure we are on the same path here…

    I wish to have the content from the meta show up in the ‘source‘ of the page, NOT the page itself. Just like a normal page meta-description appears.

    Would you rather I email you directly on this? As I am using your time I am happy to pay you in some way. Just let me know.

    Regards,

    Ray

    Plugin Author elebail

    (@elebail)

    Hello Ray,

    1) Yes the “get_terms_meta” function require the Category ID.

    2) For the “where” question:
    You need to put the code into the “header” section of your template just after the other “meta” section. (I don’t have your theme files so I can’t tell you exactly where).
    The best to do, is to make some try, and look at the HTML source code of the rendered page.

    I would add a little test in case your header is the same for all pages:

    // check we are into the category display page and the get_terms_meta function exists
    if ( is_category() && function_exists('get_terms_meta')) {
        // Retreive the meta value
        $my_decription_value = get_terms_meta($category_id, 'my_description');
        // write the meta value in the output HTML
        echo '<meta name="description" content="'.$my_decription_value.'" />';
    }

    Regards,
    Eric

    Thread Starter ratreides

    (@ratreides)

    Hi Eric,

    Thank you again for your help and time.

    Unfortunately I have been unable to achieve what I wanted and this is due to my lack of expertise and not your plugin. Could be a theme issue as well.

    Due to lack of time working on the site in question I will give up for now and try to get a solution in the longer term.

    Thank you again for your time, couldn’t have asked for better support!

    Regards,

    Ray

    Check this out guys, I’ve got this code working to pull an image field I created from this plugin. Looks like it’s working well. I’m going to now use timthumb to dynamically resize it and will post an update. But for now here’s the code:

    <?php $categoryArray = get_the_category($post->ID);
    $thisCat = $categoryArray[0]->term_id;      if(function_exists('get_terms_meta')) {
    $categoryImg =  get_terms_meta($thisCat, 'brand-image'); echo $categoryImg[0];
    } ?>

    Here’s another bit of code that uses timthumb:

    <?php $categoryArray = get_the_category($post->ID);  $thisCat = $categoryArray[0]->term_id; if(function_exists('get_terms_meta')) { $categoryImg = get_terms_meta($thisCat, 'brand-image'); } if($categoryImg[0] != NULL) : ?>
    <a href="<?php $categoryLink = get_terms_meta($thisCat, 'brand-image'); echo $categoryImg[0]; ?>" title=""><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php if(function_exists('get_terms_meta')) { $categoryImg = get_terms_meta($thisCat, 'brand-image'); echo $categoryImg[0]; } ?>&h=60&w=120&zc=1&q=100&siteName=devsally" alt="" width="120" height="60"/></a><?php endif; ?>

    Thanks dlocc, without that code snippet I’d still be forced to add images to each post thumbnail individually. This is the modified form of the code that I used, it seems a bit makeshift design but it works!

    <?php $categoryArray = get_the_category($post->ID);
    $thisCat = $categoryArray[0]->term_id;      if(function_exists('get_terms_meta')) {
    $screen =  get_terms_meta($thisCat, 'screen');
    $screen = $screen[0];
    } ?>
    <img src="<?php echo ($screen); ?>" width="55" height="55" alt=""  />

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Category Meta plugin] Where to Put Code to display Category Meta’ is closed to new replies.