2013-02-14 52 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'); 
});