Ad

How To Create Dynamic Id And Then A Link To A Post Population On A Carousel With Javascript?

- 1 answer

I would like the population on a post carousel to send me to a link and not to the post, and when is expired to be deleted automatically. You should know I'm not an expert in javascript, I did this very basic.

This is the page https://thecrescentbeachclub.com/events/upcoming-events/ and I don't know if someone can help me improve this code, or maybe create another one.

The client adds posts with featured images and then we use this module to show a carousel (they like the way is displayed now, you should know I didn't do this website neither so has been hard to change the clients mind), and when I added an automatic expirer that when the event finishes the post is deleted, all good here. The situation is that on the link I sent you I added the next code for a link because I don't want people to go to the post, I want them to go to an external link.

jQuery(function($){
$('.qode-bct-posts .qode-bct-post').each(function(){
$(this).attr('id',$(this).index()+1);
});

$('.qode-bct-posts .qode-bct-post .qode-bct-post-image img').each(function(){
$(this).unwrap();
});

$('#1').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" target="_blank" rel="nofollow noreferrer" href="https://www.eventbrite.com/e/easter-at-the-beach-buffet-brunch-tickets-58504343065" target="_blank" itemprop="url"></a>');

$('#2').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" target="_blank" rel="nofollow noreferrer" href="#" target="_blank" itemprop="url"></a>');

$('#3').wrap('<a style="width: 100%; display: inline-block; vertical-align: top;" target="_blank" rel="nofollow noreferrer" href="#" target="_blank" itemprop="url"></a>');

});

Now the issue is that when a post is deleted automatically, the link is wrong, for example, the first post has ID 1 with that link, but when expires disappears, and now the post with ID 2 has the link on 1. I have to change the link manually, and that's what we want to avoid.

Can somebody help me to make the ID dynamic so when a post expires the and disappear the others still will keep the right link? I hope I explained myself.

Ad

Answer

I ended finding a plugin that will let me add an external link to the post, instead of the post itself, so I don’t need to make this code work. I didn’t want because WordPress get all crazy when you add more plugins, but the client is happy, so I’m happy. Thanks for you help though.

Ad
source: stackoverflow.com
Ad