2013-02-14 54 views
1

我有一個非標準循環:get_the_title(),並使用它的價值

<article class="somepost"> 
     <?php  $a = get_the_title(); echo $a; ?> 
    </article> 

我如何得到一些帖子標題的價值,當我點擊了一些文章(類=「somepost」)

 $('.somempost').click(function(){ ??? }); 

Thanx。

回答

1

首先,我標題設置爲文章數據屬性:

<?php $a = get_the_title(); ?> 
<article class="somepost" data-title="<?php echo $a; ?>"> 
    <?php echo $a; ?> 
</article> 

然後在你的jQuery,設置像這樣的標題給一個變量:

$('.somepost').click(function(){ 
    var the_title = $(this).data('title'); 
});