我对javascript、php和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文件中都可以工作,例如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而不适用于链接?根本无法让它发挥作用,尽管这样的解决方案似乎是最合乎逻辑的。
然后是这个页面,它显示了一个位于<a href>
标签中间的javascript,如下所示:
<a onmousemove='"javascript:setElementCursor(this);'" href='"#'">Set the cursor for this link </a>
但是实现php post_thumbnail或其他东西对我来说已经太多了。(不管怎么说,斜杠是怎么回事?)
有什么想法吗?
无法想象你为什么要做你想做的事,但试试这个:
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;
}