2011-06-05 27 views
0

有没有人有一个想法在CSS会把下面的链接块?如何做一个WordPress的链接块?

<div class="one_third"> 
<?php 
//The Query 
query_posts('posts_per_page=1&cat=15'); 
    //The Loop 
    if (have_posts()) : while (have_posts()) : the_post(); ?> 
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
<small><?php the_time('F jS, Y') ?></small> 
    <?php if (has_post_thumbnail()) the_post_thumbnail('medium-thumbnail'); ?> 
<div class="entry"> 
<p><a style="display: block;" rel="bookmark" href="<?php the_permalink(); ?>"><?php echo strip_tags(get_the_excerpt());?></a></p> 

对不起,没有职位符合您的条件。

感谢

+0

你能发表吗?生成的html和你的css? – Sotiris 2011-06-05 15:52:37

+1

你是什么意思的一个“链接块”?你想要禾潜水工作就像一个链接? – 2011-06-05 16:04:50

+0

@大卫是的,我希望“one_third”div包装内的所有东西都成为一个链接。请参阅下面的代码。 感谢 – Nsokyi 2011-06-06 19:07:27

回答

0

@Sotiris

对不起已故的答复只得到下班后在这个网站的工作。

<div class="one_third">  
    <h2><a href="http://localhost:8888/edinburghshiatsuclinic/news-offers/news-letters-suday-test-post/." rel="bookmark" title="Permanent Link to News Letters Suday test post">News Letters Suday test post</a></h2> 
<small>May 15th, 2011</small> 
    <div class="thumbnail"><a href="http://localhost:8888/edinburghshiatsuclinic/news-offers/news-letters-suday-test-post/." title="News Letters Suday test post"><img width="190" height="140" src="http://localhost:8888/edinburghshiatsuclinic/wp-content/uploads/2011/05/front-page3-200x147.jpg" class="attachment-medium-thumbnail wp-post-image" alt="front-page3" title="front-page3" /></a></div> <div class="entry"> 

    <p><a style="display: block;" rel="bookmark" href="http://localhost:8888/edinburghshiatsuclinic/news-offers/news-letters-suday-test-post/.">Suspendisse tempus semper dignissim. Pellentesque ac tempus ligula. Aenean eu nisi eu mi consequat vehicula venenatis et leo. Praesent ornare aliquam ultricies. Nunc justo tellus, varius quis viverra a, scelerisque non justo. Suspendisse leo turpis, elementum in dignissim sed, facilisis &hellip; Continue reading &rarr;</a></p> 
</div> 
</div> 
0

好吧,根据您发布的代码,div中的所有内容都已经是链接了。如果你想单击div上的任意位置来像链接一样工作,则需要使用Javascript--不能在块内元素(<a>)中包含块级元素(<div>)。

这里是一个jQuery的方式来做到这一点:

$('#one_third').click( function(){ $(this).find('h2 a').click(); });

它只是说“当你点击ID为'one_third'股利,寻找其中的元素'h2 a'并触发该元素上的点击(我把它缩小到只是其中一个链接,如果你没有这样做,如果你刚才说的话('a'),它会点击所有的链接,这也许会很有趣。)

+0

感谢大卫, 我试过 \t <脚本类型= “文/ JavaScript的”> \t \t的jQuery(函数(){ \t \t $( 'one_third')。点击(函数(){$(这个).find('h2 a')。click();}); \t 但是没有运气? – Nsokyi 2011-06-12 12:34:09

+1

我看到你已将'#one_third'改为'.one_third',这对你的代码是正确的。也包装了'jQuery(function(){',我猜想因为Wordpress可能会与其他库冲突,如果你这样做的话,确保你正在关闭函数,尝试添加另一个'});'at最后,像这样: 'one_third ' '<脚本类型= “文本/ JavaScript的”> jQuery的(函数(){ $()点击( \t函数(){ \t $(本).find(' H 2的' )。单击(); \t}); }); ' – 2011-06-13 03:17:22

+0

当然,请确保您链接到jQuery的工作版本。 我喜欢做的事情,如果你使用的是Firebug,Safari或Chrome,请在代码中添加'console.log($(this));'(这里我将它放在最内层的函数中)。如果它记录了一个错误或者意想不到的事情,它可以帮助你找到问题所在。 – 2011-06-13 03:20:14