Site icon WP Smith

Slight Upgrade/Revision to WP-Cycle to Allow Page IDs

One thing that has bugged me about WP-Cyle is that I had to include hard-coded URLs to linkify the rotating images. This is problem matic when I change my URLs, etc. So I just want to enter page IDs and allow WordPress to properly assign the proper URL. Download the revised/upgraded WP Cycle: [download id="12"].

For those who want to know what I did, here's what I added:

On line 393, the original code contains:
[php]if($value['image_links_to'])
$input[$key]['image_links_to'] = clean_url($value['image_links_to']);[/php]

I changed it to:
[php]if($value['image_links_to']) {
$checkhttp = substr($value['image_links_to'], 0, 4);
if ($checkhttp == 'http')
$input[$key]['image_links_to'] = clean_url($value['image_links_to']);
}[/php]

Then on line 416 in the foreach section, the original code contains:
[php]foreach((array)$wp_cycle_images as $image => $data) {
if($data['image_links_to'])
echo '<a href="'.$data['image_links_to'].'">';

echo '<img src="'.$data['file_url'].'" width="'.$wp_cycle_settings['img_width'].'" height="'.$wp_cycle_settings['img_height'].'" class="'.$data['id'].'" alt="" />';

if($data['image_links_to'])
echo '</a>';

echo $newline;
}
[/php]

I changed it to:
[php highlight="2,3,4,5,6,7,8"]foreach((array)$wp_cycle_images as $image => $data) {
if($data['image_links_to']) {
$checkhttp = substr($data['image_links_to'], 0, 4);
if ($checkhttp != 'http') {
$id = intval($data['image_links_to']);
$data['image_links_to'] = get_permalink( $id );
}
echo '<a href="'.$data['image_links_to'].'">';
}

echo '<img src="'.$data['file_url'].'" width="'.$wp_cycle_settings['img_width'].'" height="'.$wp_cycle_settings['img_height'].'" class="'.$data['id'].'" alt="" />';

if($data['image_links_to'])
echo '</a>';

echo $newline;
}
[/php]