WordPress.org

Ready to get started?Download WordPress

Forums

Slider links in php (4 posts)

  1. dunbicake
    Member
    Posted 1 year ago #

    I would like to add links to the slider on this website - http://www.drblen.com.

    Here is the code that the template uses for the slider:

    <?php $limittext = $limit;?>
    <?php global $more;	$more = 0; $counter=1;?>
    <?php query_posts("posts_per_page=5&post_type=slider");?>
    <?php if(have_posts()) { ?>
    <ul class="kwicks horizontal">
    	<?php while (have_posts()) : the_post(); ?>
    
    		<?php
    			$custom = get_post_custom($post->ID);
    			$custom = get_post_custom($post->ID);
    			$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'slider-post-thumbnail' );
    			$url = $thumb['0'];
    			$thumb = $custom["thumb"][0];
    			$sliderurl = $custom["slider-url"][0];
    		?>
    
    		<li><span class="shadow"></span>
    			<?php echo '<div class="thumb">'; ?>
    				<div class="bg" style="background-image:url(<?php echo $url; ?>)" ></div>
    			<?php echo '</div>'; ?>
    
    			<div class="desc color-<?php echo $counter; ?>">
    				<div class="left-bg">
    					<a href="<?php the_permalink(); ?>" class="left-bg"><?php the_title('<h2>','</h2>'); ?></a>
    					<div class="excerpt">
    						<?php the_excerpt();  ?>
    					</div>
    					<a href="<?php the_permalink(); ?>" class="kwick-button">read more</a>
    				</div>
    			</div>
    
    		</li>
    	<?php $counter++; endwhile; ?>
    	<?php wp_reset_query(); ?>
    </ul>
    <?php } else { ?>
    		<div id="attention-box">
    			<div id="att-box-inner">
    			<div class="attention-box alert-box" style="margin: 150px 20px 0 20px;">You don't have any <strong>Slides</strong>. You need to create them using <strong>Slides</strong> custom post type.</div>
    			</div>
    		</div>
    	<?php } ?>
    <?php wp_reset_query();?>

    Any help would be greatly appreciated. Thanks!

  2. bcworkz
    Member
    Posted 1 year ago #

    What links do you want to add and how would they look? I see the title and read more links below the images, what else should there be?

  3. dunbicake
    Member
    Posted 1 year ago #

    My client wants the images themselves to be hyperlinked as well. He knows the other links are there, but really wants the images to be clickable.

    Any ideas?

    I've tried a few things to know avail.

  4. bcworkz
    Member
    Posted 1 year ago #

    Seems like a reasonable request. Normally, you would use get_the_permalink() to get the link into a variable, then extract the link text and replace it with an image. Except there's no image there and there's nothing to click on. The image we see is a background element, which allows the slider to quickly and smoothly alter the image limits seen.

    You will need to use javascript or jQuery (jQuery would be way easier for this) to see the click event and "click" the link on the user's behalf. To pass the post/page ID to javascript, add an id attribute to the element the click listener is attached to via template script. Onclick, extract the ID from the element id value then do window.location = 'index.php?p=' + post_id;

Topic Closed

This topic has been closed to new replies.

About this Topic