Adding a link to featured image in a custom post
-
Hi, I’m converting a template I made to a wordpress theme. I have a carousel on my front page. I used bootstrap while writing the template, and to integrate the carousel with wordpress, I registered it as a custom post. I want the pictures in the slider to link to specific pages, but they themselves won’t be on those pages.
I googled how to do something like this, tried several approaches, but nothing worked. In my front page file I’m calling the slider like this:<div class="carousel-inner" role="listbox"> <?php $slider = get_posts(array('post_type' => 'slider', 'posts_per_page' => 5)); ?> <?php $count = 0; ?> <?php foreach($slider as $slide): ?> <div class="item <?php echo ($count == 0) ? 'active' : ''; ?>"> <a href=""><img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($slide->ID)) ?>"></a> </div> <?php $count++; ?> <?php endforeach; ?> </div>
and I’m pretty sure that this could be solved by adding relevant php code inside the link tag but I have no idea what would that relevant code be.
I tired using custom fields for this, but it didn’t work. I tired plugins, also without any success. The closest I got to a solution was by adding<?php echo get_post_meta($Post->ID, "slider-url", true); ?>
inside the link tag, but this just links all the images to my front page, and I have no idea how to modify the code so it would do what I want.
- The topic ‘Adding a link to featured image in a custom post’ is closed to new replies.