Elementar
Elementar

Reputation: 13

get_the_title() of some post and work with it's value

I have a standart loop with:

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

How I get value of some post's title, when I click on some article (class="somepost")

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

Thanx.

Upvotes: 1

Views: 473

Answers (1)

n_i_c_k
n_i_c_k

Reputation: 1534

First, I would set the title to the articles data attribute:

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

Then in your jQuery, set the title to a variable like so:

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

Upvotes: 1

Related Questions