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]"); ?>
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
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
}