2014-09-03 88 views
1

我太新來javascript,php和wordpress來弄清楚自己,所以也許有人可以幫助我。當懸停在帖子鏈接上時,我可以使用張貼縮略​​圖作爲光標圖像嗎? (wordpress)

我在wordpress上製作一個投資組合頁面。所有的帖子標題都在sidebar.php文件中循環。我希望這樣做,以便當您將鼠標懸停在帖子的標題上時,光標將變爲帖子的精選圖片/帖子縮略圖。

的谷歌搜索的最常見的結果是簡單的CSS版本,這樣的事情:

.sidebar {cursor:url('img.png') auto} 

,所以我有這個:

.sidebar a:hover{ 
    cursor:url('<?php if(has_post_thumbnail()){ 
    the_post_thumbnail('thumbnail');}?>') auto; 
    border-bottom: 2px dashed; 
    border-color: blue; 

,但它不工作。當php放在任何php文件中時,php會工作,例如,sidebar.php,然後縮略圖在帖子標題下。

另一種選擇我發現了一個JavaScript之一,它是這個頁面上:

http://www.ajaxblender.com/howto-create-custom-image-cursors.html

#test-area { 
height: 200px; 
border: 3px dashed #CCCCCC; 
background: #FFFFFF; 
padding: 20px; 
cursor: url(./blank.cur), none; 
} 

#mycursor { 
cursor: none; 
width: 97px; 
height: 137px; 
background: url("images/custom-cursor.jpg") no-repeat left top; 
position: absolute; 
display: none; 
top: 0; 
left: 0; 
z-index: 10000; 
} 

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('#test-area').mouseout(function(){ 
     $('#mycursor').hide(); 
     return >false; 
    }); 
    $('#test-area').mouseenter(function(){ 
     $('#mycursor').show(); 
     return >false; 
    }); 
    $('#test-area').mousemove(function(e){ 
     $('#mycursor').css('left', e.clientX - 20).css('top', e.clientY + 7); 
    }); 
}); 
</script> 

,但我認爲這只是div的,而不是鏈接的作品?根本無法讓它工作,雖然這樣的事情似乎是最合乎邏輯的解決方案。

,並隨後把this page,顯示只是在<a href>標籤這樣的中間一個javascript:

<a onmousemove=\"javascript:setElementCursor(this);\" href=\"#\">Set the cursor for this link </a> 

,但實施中就有一個PHP post_thumbnail什麼的已經太多了我。 (不管怎樣,斜線怎麼了?)

有什麼想法嗎?

+0

你把那個CSS放在CSS文件或sidebar.php文件中? PHP不會在css文件中工作 – Howli 2014-09-03 21:45:29

+0

將url保存在一個隱藏的變量中,並寫入懸停的js函數以將光標切換到縮略圖並且默認 – Sunand 2014-09-03 21:46:05

回答

0

無法想象爲什麼你想,做你想做的,但試試這個:

IN的header.php

<?php 
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'YOUR_THUMB _SIZE'); 
?> 

現在你的CSS這必須放置在header.php文件以及

.sidebar a:hover{ 
    cursor:url('<?php echo $thumb['0']; ?>') auto; 
    border-bottom: 2px dashed; 
    border-color: blue; 
} 
相關問題