admin管理员组文章数量:1415653
I'm using Elementor 2.6.8 + Elementor Pro 2.6.2
I'm designing an Archive template to display a list of Custom Post Types filtered by custom taxonomy terms. I'm using Posts Widget from Elementor Pro to do this without a line of code.
Also, thanks to Ele Custom Skin plugin (1.2.0), I can design each post skin in a custom way (hopefully Elementor Pro will provide this in the future)/
Now, I want to display, in each post, the post's current position in the list (=in the WP loop).
I tried with this code snippet that I added to each post with the ShortCode Widget.
add_shortcode( 'current_post_count', function () {
global $wp_query;
$out = $wp_query->current_post;
return $out;
} );
But this always return -1.
I suppose the reason is that, in the context of the Posts Widget, the global $wp_query is not the one to get the info from. I suppose the widget use another variable. But thenm I don't know how to achieve this. Maybe if I could get the actual $query variable in use ? Or maybe use the Query ID parameter offered by the Posts Widget?
I don't know how to get this to work.
Anything to point me towards the right direction guys? thanks!
I'm using Elementor 2.6.8 + Elementor Pro 2.6.2
I'm designing an Archive template to display a list of Custom Post Types filtered by custom taxonomy terms. I'm using Posts Widget from Elementor Pro to do this without a line of code.
Also, thanks to Ele Custom Skin plugin (1.2.0), I can design each post skin in a custom way (hopefully Elementor Pro will provide this in the future)/
Now, I want to display, in each post, the post's current position in the list (=in the WP loop).
I tried with this code snippet that I added to each post with the ShortCode Widget.
add_shortcode( 'current_post_count', function () {
global $wp_query;
$out = $wp_query->current_post;
return $out;
} );
But this always return -1.
I suppose the reason is that, in the context of the Posts Widget, the global $wp_query is not the one to get the info from. I suppose the widget use another variable. But thenm I don't know how to achieve this. Maybe if I could get the actual $query variable in use ? Or maybe use the Query ID parameter offered by the Posts Widget?
I don't know how to get this to work.
Anything to point me towards the right direction guys? thanks!
Share Improve this question asked Aug 17, 2019 at 0:53 Jess8bitJess8bit 113 bronze badges1 Answer
Reset to default 1I have solved my issue by using a more recent version (1.1.1) of Elementor Custom Skin Pro plugin, which allows to use dynamic values directly in the template content, that are interpreted during the Loop. In my case, {{index}} does the trick.
本文标签: wp queryDisplay current post position in Elementor Posts widget
版权声明:本文标题:wp query - Display current post position in Elementor Posts widget 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745187826a2646768.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论