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
1 Answer
Reset to default 0Here'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
版权声明:本文标题:loop - How to show post views shortcode data for each post on Posts List Page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736670161a1946877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论