display text if post in a certain category

patrick's Avatar

patrick

05 Jul, 2019 12:25 PM

Hi,
I would like to display the tekst "Sponsored post" in a slider if one of the categories from that post is the category "sponsored".
Can you tell me how to make this condition?

Thanks!

  1. Support Staff 1 Posted by Dmitry Semenov on 05 Jul, 2019 02:50 PM

    Dmitry Semenov's Avatar

    Hello,

    You may create a custom variable as described here: http://help.dimsemenov.com/kb/wordpress-royalslider-advanced/wp-add...

    Here is a basic example:

    function slider_show_sponsored($m, $data, $options) {
      $m->addHelper('sponsored_badge', function() use ($data) {
        if ( isset($data->ID) && has_category('my-category', $data->ID) ) {
          return 'Sponsored';
        }
      } );
    }
    add_filter('new_rs_slides_renderer_helper','slider_show_sponsored', 10, 4);
    

    (will display text "Sponsored" for variable {{sponsored_badge}})

    https://developer.wordpress.org/reference/functions/has_category/

  2. 2 Posted by patrick on 10 Jul, 2019 11:15 AM

    patrick's Avatar

    Excellent!
    Thanks Dmitry!!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac