admin管理员组

文章数量:1125900

Example: [shortcode id=""]. I just want to how to dynamically fetch each post ID on Posts Lists page over archive page or normal posts page inside the shortcode placed in excerpt.

Currently I'm using Post Views plugin. Using its shortcode [post-views], I'm able to correctly display post view on each single post page. However I'm facing issue when I include the same shortcode in Excerpt to show it over Posts List Page and Archive List page. There it appears Zero.

It works fine on Posts List page, only if I give a absolute Post ID as : [post-views id="1"], currently don't have a way to fetch that ID dynamically, as get_the_ID() fetches the page ID.

While on Archive page, Shortcode syntax appear as its is in Excerpt.

Hence Could you please help extend that shortcode to auto fetch Post id even on Post Lists Page or Archive page?

Example: [shortcode id=""]. I just want to how to dynamically fetch each post ID on Posts Lists page over archive page or normal posts page inside the shortcode placed in excerpt.

Currently I'm using Post Views plugin. Using its shortcode [post-views], I'm able to correctly display post view on each single post page. However I'm facing issue when I include the same shortcode in Excerpt to show it over Posts List Page and Archive List page. There it appears Zero.

It works fine on Posts List page, only if I give a absolute Post ID as : [post-views id="1"], currently don't have a way to fetch that ID dynamically, as get_the_ID() fetches the page ID.

While on Archive page, Shortcode syntax appear as its is in Excerpt.

Hence Could you please help extend that shortcode to auto fetch Post id even on Post Lists Page or Archive page?

Share Improve this question edited Aug 7, 2019 at 9:16 parmanand asked Aug 6, 2019 at 14:04 parmanandparmanand 1014 bronze badges 2
  • I'm sorry to disappoint you, but that is a specific plugin question, which you should ask the developer of the plugin for. – user3135691 Commented Aug 6, 2019 at 15:14
  • I asked them, but they unresponssive. However my only question is: how to fetch Post ID on posts list page in a shortcode place. Example: [post-views id="<place>"] – parmanand Commented Aug 7, 2019 at 9:14
Add a comment  | 

1 Answer 1

Reset to default 0

Here's the code I use:

<?php if (shortcode_exists('post-views')) echo do_shortcode('[post-views id="'.$post_id.'"]'); ?>

The if condition first checks if the plugin is active. The Post ID is my variable $post_id.

If you are inside The Loop you can get the Post ID in the loop with $post_id = get_the_ID().

本文标签: loopHow to show post views shortcode data for each post on Posts List Page