• Hi all,
    my website is Il tuo giapponese, it’s running on a WordPress 3.8.1, my Customizr version is 3.1.6 and my need is to add some Amazon links (that I already know) in the left column of my post layout; these links should be also “sensitive” to the post category: certain links for category A, another set of links for category B and so on.

    What should be a smart way to get this task done? I was first thinking of using a plugin but maybe a simpler and faster solution would be to use a shortcode inside a widget that print out the Amazon link HTML code. Any idea?

    Now, the question is: does Customizr accept shortcode inside widgets? I’ve already tried on my WordPress but loooks like the theme is not accepting and executing shortcodes: am I right?

    Thank you all,
    Nicola

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter deinezauber

    (@deinezauber)

    Ok I think I’ve find out how to activate shortcode execution:

    add_filter('widget_text', 'do_shortcode');

    This PHP statement, saved inside my child theme functions.php, does the job; now I’m going to check how to detect post category…

    Thread Starter deinezauber

    (@deinezauber)

    Good, for detecting a post category the WordPress API offers the function ‘in_category’; using this function it’s possibile to test for post category, including the HTML file with the Amazon links and having them displayed inside the widget.

    Any other better idea?

    Thread Starter deinezauber

    (@deinezauber)

    By the way, this is the snippet code I’ve added in my functions.php:

    /* Activate widget shortcode execution */
    add_filter('widget_text', 'do_shortcode');
    
    /* Shortcode for printing Amazon links, depending on post category */
    function printAmazonLinks(){
    
            if(in_category('A')){
    
            //Stuff related to category 'A'
            $widgetContent = ...
    
            } else if(in_category('B')){
    
            //Stuff related to category 'B'
            $widgetContent = ...
    
            } else {
    
            //Default staff
            $widgetContent = ...
    
            }
    
    	return $widgetContent;
    }
    add_shortcode('print_Amazon_links', 'printAmazonLinks');
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Amazon affiliate, widgets and shortcodes’ is closed to new replies.