WordPress.org

Ready to get started?Download WordPress

Forums

TBTestimonials
Return the category (9 posts)

  1. joel.a.taylor
    Member
    Posted 1 year ago #

    So one big thing that seems to be missing from this plugin is that it doesn't return the Category of the testimony.

    http://wordpress.org/extend/plugins/tb-testimonials/

  2. Travis Ballard
    Member
    Plugin Author

    Posted 1 year ago #

    can you explain a little further? I added in stuff the other day for it to show a listing a based on a category. Haven't tagged it to a new version yet as I'm working on other goodies before I do.

  3. joel.a.taylor
    Member
    Posted 1 year ago #

    %category% - or - %categories% should be one of the tags accepted by the template. That's what I mean. I guess it could get a lil complicated if a post is associated to multiple categories.

  4. Travis Ballard
    Member
    Plugin Author

    Posted 1 year ago #

    I just added an update with a new template api. you can add the tag yourself by adding this to your functions.php. after that you can use it however you like.

    add_action( 'tbt_template_functions', 'add_category_to_tbtestimonials' );
    
    /**
    * add a 'category' variable to tbt
    *
    * @param mixed $twig
    */
    function add_category_to_tbtestimonials( $twig ){
        $twig->addGlobal( 'category', call_user_func( 'my_category_func' ) );
    }
    
    /**
    * callback for category tag
    *
    */
    function my_category_func()
    {
        $categories = wp_get_object_terms( get_the_ID(), 'tbtestimonial_category' );
        if( isset( $categories[0]->name ) )
            return $categories[0]->name;
    }
  5. Travis Ballard
    Member
    Plugin Author

    Posted 1 year ago #

    or you could return $categories ( wp_get_object_terms() call ) and then do a loop in the template to display more than 1 category.

    Template Example:

    {% if category %}
      Categories:
      {% for cat in category %}
          <span class="category">{{ cat.name }}</span>
      {% endfor %}
    {% endif %}

    New my_category_func for functions.php that returns array

    /**
    * callback for category tag
    *
    */
    function my_category_func(){
        return wp_get_object_terms( get_the_ID(), 'tbtestimonial_category' );
    }
  6. joel.a.taylor
    Member
    Posted 1 year ago #

    Awesome! Thx.

    Great support. :)

  7. companyjuice
    Member
    Posted 1 year ago #

    I didn't want to open a new discussion, because the title would be the same, however...

    I can't seem to output the shortcode for a testimonial "category" like such:
    [testimonial cat='Technology' template='shortcode']

    But this works, without the category filter:
    [testimonial id='all' template='shortcode']

    I am testing with only 1 testimonial. I am positive that 1 testimonial has been assigned the category 'Technology'. I'm thinking this should work, but there is no output.

  8. Travis Ballard
    Member
    Plugin Author

    Posted 1 year ago #

    Tryin cat="technology" just for giggles

  9. companyjuice
    Member
    Posted 1 year ago #

    Hey Travis. Thanks for the quick reply!

    Trying [testimonial cat="technology"] did not work either.

    Let me know if you'd like me to try other things.

    Cheers,
    Marty

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.