• Resolved zsolt

    (@zsolt82)


    Hello Greg

    How do I add the short code for the post wiew counter to my ads?

    <?php echo do_shortcode(“[post-views]”); ?>

    I want a method like Show Ad-id

    Thanks in advance, Greg

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i understand you want to show the number of views the Ad user is currently looking at has? If so then would the [post-views] shortcode know what number to show?

    Either way, to display it you can copy the code you from the linked article and only replace

    
    <?php esc_html_e( $post_id ) ?>
    

    with

    
    <?php echo do_shortcode("[post-views]"); ?>
    
    Thread Starter zsolt

    (@zsolt82)

    Hello

    Does not work.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    what do you mean by “does not work”?

    Thread Starter zsolt

    (@zsolt82)

    Hello

    add_action( "adverts_tpl_single_details", "my_adverts_tpl_single_show_id" );
    function my_adverts_tpl_single_show_id( $post_id ) {
        ?>
        <div class="adverts-grid-row">
        <div class="adverts-grid-col adverts-col-30">
        <span class="adverts-round-icon adverts-icon-wordpress"></span>
        <span class="adverts-row-title">ID</span>
        </div>
        <div class="adverts-grid-col adverts-col-65">
        <?php esc_html_e( $post_id ) ?>
        </div>
        </div>
        <?php 
    }
    add_action( "adverts_tpl_single_details", "my_adverts_tpl_single_show_id" );
    function my_adverts_tpl_single_show_id( $post_id ) {
        ?>
        <div class="adverts-grid-row">
        <div class="adverts-grid-col adverts-col-30">
        <span class="adverts-round-icon adverts-icon-wordpress"></span>
        <span class="adverts-row-title">ID</span>
        </div>
        <div class="adverts-grid-col adverts-col-65">
        <?php echo do_shortcode("[post-views]"); ?>
        </div>
        </div>
        <?php 
    }

    Code 2 together causes an error

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    ohh ok, you cannot use it like that because you are registering the my_adverts_tpl_single_show_id() function twice which will always cause a fatal error.

    Try changing the second code to

    
    add_action( "adverts_tpl_single_details", "my_adverts_tpl_single_show_post_views" );
    function my_adverts_tpl_single_show_post_views( $post_id ) {
        ?>
        <div class="adverts-grid-row">
        <div class="adverts-grid-col adverts-col-30">
        <span class="adverts-round-icon adverts-icon-wordpress"></span>
        <span class="adverts-row-title">Post Views</span>
        </div>
        <div class="adverts-grid-col adverts-col-65">
        <?php echo do_shortcode("[post-views]"); ?>
        </div>
        </div>
        <?php 
    }
    
    Thread Starter zsolt

    (@zsolt82)

    Hi,

    ooo I understand

    Thank you Greg

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show post view’ is closed to new replies.