Viewing 15 replies - 1 through 15 (of 22 total)
  • Plugin Contributor Pippin Williamson

    (@mordauk)

    You can already do this, though it largely depends on your theme.

    Are the the developer that built your theme, or are you comfortable modifying it?

    What theme are you using?

    Thread Starter Rafał

    (@ayek)

    Usually modifying Twentyeleven

    Plugin Contributor Pippin Williamson

    (@mordauk)

    If you are using Twenty Eleven, you should already have CSS classes added to the “body” tag for the post type. The category and tag might also be there, but I don’t think so.

    See this page for info on adding new classes: http://codex.wordpress.org/Function_Reference/body_class

    The taxonomy for tags/categories is “download_tag” and “download_category”.

    Does that tell you what you need?

    Thread Starter Rafał

    (@ayek)

    Hi mordauk
    I’m not a programmer, and I find it hard to talk about PHP coding 🙁

    Twenty Eleven is very well equipped with CSS classes, and I can use them (adjusting the template), because they are already! 🙂

    But..
    How to modify the EDD templates to using classes of EDD taxonomy?

    How to display the current category and current tags (in footnotes of each item page, search results, and checkout) – for informational purposes, and as links to lists of other downloads (for tracking chosen category/tag)?

    Please, is there a piece of code that gets and shows the current download taxonomy?

    Plugin Contributor Pippin Williamson

    (@mordauk)

    Just to make sure I have this right:

    1. You want to add CSS class names to your template that contain the names of the current download tags/categories.

    2. You want to show the tags/categories applied to the current download somewhere on the download details page.

    Correct?

    Thread Starter Rafał

    (@ayek)

    Yes, correct!

    with a little clarifying:
    …CSS class names, that contain the slugs of the current download tags/categories.

    Plugin Contributor Pippin Williamson

    (@mordauk)

    Add this to your functions.php, it should do the trick:

    function download_category_id_class($classes) {
        global $post;
        foreach((get_the_terms($post->ID), 'download_category') as $category)
            $classes[] = $category->slug;
            return $classes;
    }
    add_filter('post_class', 'download_category_id_class');
    
    function download_tag_id_class($classes) {
        global $post;
        foreach((get_the_terms($post->ID), 'download_tag') as $tag)
            $classes[] = $tag->slug;
            return $classes;
    }
    add_filter('post_class', 'download_tag_id_class');
    Thread Starter Rafał

    (@ayek)

    I like you wanted to figure out, but…
    Parse error: syntax error, unexpected ‘,’ in /wp-content/themes/twentyten/functions.php on line:
    foreach((get_the_terms($post->ID), 'download_category') as $category)

    Plugin Contributor Pippin Williamson

    (@mordauk)

    Whoops, it should be this:

    function download_category_id_class($classes) {
        global $post;
        foreach(get_the_terms($post->ID), 'download_category') as $category)
            $classes[] = $category->slug;
            return $classes;
    }
    add_filter('post_class', 'download_category_id_class');
    
    function download_tag_id_class($classes) {
        global $post;
        foreach(get_the_terms($post->ID), 'download_tag') as $tag)
            $classes[] = $tag->slug;
            return $classes;
    }
    add_filter('post_class', 'download_tag_id_class');
    Thread Starter Rafał

    (@ayek)

    The same error, on the same line:
    foreach(get_the_terms($post->ID), 'download_category') as $category)

    Plugin Contributor Pippin Williamson

    (@mordauk)

    Sorry, fixed:

    function download_category_id_class($classes) {
        global $post;
        foreach( get_the_terms( $post->ID, 'download_category' ) as $category ) {
            $classes[] = $category->slug;
        }
    	return $classes;
    }
    add_filter('post_class', 'download_category_id_class');
    
    function download_tag_id_class($classes) {
        global $post;
        foreach( get_the_terms( $post->ID, 'download_tag' ) as $tag ) {
            $classes[] = $tag->slug;
    	}
        return $classes;
    }
    add_filter('post_class', 'download_tag_id_class');
    Thread Starter Rafał

    (@ayek)

    This goes in the right direction – EDD-from classes have been added
    But… 🙂
    On every post which has no tag or/and no category chosen WP echoes this:

    Warning: Invalid argument supplied for foreach() in /wp-content/themes/twentyten/functions.php

    Pages have no tags and aren’t assigned to any category, so every page displays the double warning, and additionally prints classes:

    Warning: Invalid argument supplied for foreach() in /wp-content/themes/twentyten/functions.php on line … (for category)

    Warning: Invalid argument supplied for foreach() in /wp-content/themes/twentyten/functions.php on line … (for tag)
    class=”post-123 page type-page status-publish hentry”>

    Maybe some conditional loop will help? else/if? I don’t know how to use it…

    Thread Starter Rafał

    (@ayek)

    For standard post (not from EDD) there is double error, too.

    Warning: Invalid argument supplied for foreach() in /wp-content/themes/twentyten/functions.php on line … (accordingly for category)

    Warning: Invalid argument supplied for foreach() in /wp-content/themes/twentyten/functions.php on line … (accordingly for tags)
    class=”post-1 post type-post status-publish format-standard hentry category-uncategorized tag-tag1″>

    Plugin Contributor Pippin Williamson

    (@mordauk)

    This will fix it:

    function download_category_id_class($classes) {
       global $post;
       $categories = get_the_terms( $post->ID, 'download_category' );
       if( $categories ) {
    	    foreach( $categories as $category ) {
    	        $classes[] = $category->slug;
    	    }
    	}
    	return $classes;
    }
    add_filter('post_class', 'download_category_id_class');
    
    function download_tag_id_class($classes) {
       global $post;
       $tags = get_the_terms( $post->ID, 'download_tag' );
       if($tags) {
    	    foreach( $tags as $tag ) {
       	     $classes[] = $tag->slug;
    		}
    	}
       return $classes;
    }
    add_filter('post_class', 'download_tag_id_class');
    Thread Starter Rafał

    (@ayek)

    You are GREAT! 🙂 Thank you!!!

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘[Plugin: Easy Digital Downloads] Using tags and categories’ is closed to new replies.