I want to "mark" the last 100 posts with a transparent .png "NEW".
I cannot use the date of the last posts, as i use older dates for my post entries.
So I would have to use the post ID for this.
I can overlay the posts with a transparent png in the view like this (with additional .css of course):
But this would mark ALL the posts as new - of course.
Is it possible to query for the last 100 posts with a javascript within the view? (or in the loop?)
And if so, can you help me?
Unfortunately at this time it isn't possible to do this since we are not able to create a loop counter. However I know that in our patch next week we would be getting a loop counter.
This way you can use our conditional shortcode to check which count you are at in the loop and add your overlay. I would highly advise waiting on this update as it would make this much easier.
Right now a custom solution would be needed to keep track of the current loop count.
Hello Shane,
thanks for the code, one question though, is lte or 100 referring to the 100 last entries, so internally the system is looking at the post ID? Or is it view/loop dependend. What I mean is- does it just "mark" the first 100 entries of the search. (Which would change with every new search - of course.
How it works is that the [wpv-loop-index] shortcode is just an index counter that increments each time a new post is displayed.
It actually keeps track of which number post its displaying. The 100 in my previous post is the index at which you want the loop to stop displaying the "New " overlay.
It Marks the first 100 entries and anything beyond the first 100 entries are displayed normally.
Hi Shane,
I tested it - and as I thought it does mark the first 100 entries in the view with my "new" overlay.
But this is not what I need, because it changes based on the filtering or sorting the user does.
What I need is the 100 latest posts - marked with "new" - and this is only possible with the post-id of the displayed post.
Only if the last 100 posts (by ID) are called, they remain the same no matter how the user is sorting or filtering the view.
I mean there isn't a way to tell by using the post ID's which are the newest posts. This is done by the post date. So it will complicate things in the filter because lets say your users do a search, however only 2 of your newest 100 posts will show up.
The only way I see this working is by using some custom code to mark a post as new when it is created and then remove the last 100th post from being new.
So some custom code is needed here which would be out of the scope of our support forum. The best I can do right now is to advise of where you can get assistance with the custom code. https://toolset.com/contractors/
Because the only facility we have for this right now is to use the index counter.
Obviously the post's with the highest ID are the latest posts. So I would need a script that uses the 100 highest post ID#s and then I could mark them as "new"
I thought something like this would be possible with toolset.
It is possible through these means but you have to remember that we need a starting value to get the latest 100. The post ID's are shared amongst all the posts and post types in wordpress.
This means that if CPT A has a post id of 100 and we create a Post in CPT B this will give it an ID of 101 but if we go back to CPT A and create a post it will give us 103.
So at any given point we don't know which value would be the highest. It is also possible that the post ID goes beyond 1000 as well.
It isn't a safe alternative because eventually it would need some re-adjusting to get additional posts that are beyond your starting value.
Another alternative is that you can get all the post ID's and then you sort it and get the ID's of the latest 100 and store it into a shortcode array, then check if the ID of the Post that is being output by view is one that is in that array.
This one seems like it could work.
Please let me know if this helps because we might be able to write up a shortcode for this.
Another alternative is that you can get all the post ID's and then you sort it and get the ID's of the latest 100 and store it into a shortcode array, then check if the ID of the Post that is being output by view is one that is in that array.
This would be fine with me, I am aware that the post ID of all the post includes pages etc. So my 100 would be maybe only 95 if 5 other posts were made. But this is ok, as nobody is counting the latest 100 entries in the list I am marking as "new"