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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

I 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