Please take a look at the code below:
<ul id="all-movies">
<li class="movie">
<img src="pic.jpg" />
</li>
<li class="movie featured">
<img src="pic.jpg" />
</li>
<li class="movie featured">
<img src="pic.jpg" />
</li>
</ul>
In the code above, I would like to prepend <a href="<?php bloginfo('url'); ?>/hello"></a>
to the li
elements with a class of featured
so that it looks like this:
<ul id="all-movies">
<li class="movie">
<img src="pic.jpg" />
</li>
<li class="movie featured">
<a href="<?php bloginfo('url'); ?>/hello"></a>
<img src="pic.jpg" />
</li>
<li class="movie featured">
<a href="<?php bloginfo('url'); ?>/hello"></a>
<img src="pic.jpg" />
</li>
</ul>
And <?php bloginfo('url'); ?>
will be replaced with my site.
How can I get this to work? I have tried something like the following but it didn't work:
$("#all-movies li").hasClass('featured').prepend('<a href="<?php bloginfo('url'); ?>/hello"></a>');
Note: The featured
class is being added dynamically.
-edit- This is the code I'm using to add the featured
class dynamically:
function wpse80098_filter_post_class( $classes ) {
global $post;
if ( 'yes' == get_post_meta( $post->ID, '_jsFeaturedPost', true ) ) {
$classes[] = 'featured';
}
return $classes;
}
add_filter( 'post_class', 'wpse80098_filter_post_class' );