• I got my first plugin, shortcode is one that needs to be written on each blog entry, and prints its output in the same place where the shortcode is written.

    Everything works fine, but now I want to print in the sidebar, either within a text widget that is no longer displayed in the content.

    I need to continue writing in the blog entry content, but to display the result in a widget in the sidebar.

    I leave my current code plugin

    <?php
    
    add_shortcode('mark', 'relacionarBrandName');
    
    function relacionarBrandName($atts){
    	ob_start();
        extract( shortcode_atts( array (
            'posts' => '',
            'brand' => '',
        ), $atts ) );
    
        $options = array(
            'posts_per_page' => $posts,
            'post_type' => 'product',
            'tax_query' => array(
                array(
                'taxonomy' => 'product_brand',
                'field' => 'slug',
                'terms' => $brand
            )
          )
        ); 
    
        $products = new WP_Query( $options );
        if( $products->have_posts() ) {
          while( $products->have_posts() ) {
            $products->the_post();
            ?>
            <div class="relacional">
              <h5><?php the_title() ?></h5>
              <div class="featured-image">
             <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
              </div>
            </div>
            <?php
        return ob_get_clean();
          }
        }
        else {
          echo 'Oh ohm no productos!';
        }
    }
    ?>

    No need to bring this shorcode a widget in the sidebar

    [mark posts = "2" brand = "duck"]

    why not always be the same brand and have to bring the contents to the blog

  • The topic ‘How do I print output shortcode outside content?’ is closed to new replies.