用以下代码替换上述代码:
<?php /*
Template Name: Meet The Team Template
*/
?>
<?php get_header(); ?>
<div id="meet_posts" class="narrowcolumn">
<?php
$recent = new WP_Query("cat=6&orderby=title&order=ASC");
while($recent->have_posts()):$recent->the_post();
$desc_values = get_post_custom_values("description");
?>
<div id="meetteam_featured_image" class="<?php the_ID(); ?> team_featured_image_<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="title">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</a>
</div>
<?php endwhile ?>
<div id="image-post-info"></div>
</div>
<?php get_footer(); ?>
在函数中添加以下代码。php文件:
add_action( \'wp_ajax_ajaxified_function\', \'ajaxified_function\' );
add_action( \'wp_ajax_nopriv_ajaxified_function\', \'ajaxified_function\' );
function ajaxified_function() {
$temp = get_post($_POST[\'post_id\']);
echo $temp->post_title.\'<br/><br/>\'.$temp->post_content;
die();
}
在自定义js文件中添加以下代码:
jQuery(document).ready(function (){
jQuery(\'#meetteam_featured_image a\').on(\'click\',function(event){
event.preventDefault();
var post_id = jQuery(this).parent().attr(\'class\');
post_id = post_id.split(" ");
post_id = post_id[0];
jQuery.ajax({
type: "POST",
url: \'http://www.yoursitename.com/wp-admin/admin-ajax.php\',
data: \'action=ajaxified_function&post_id=\'+post_id,
success: function (msg) {
jQuery(\'#image-post-info\').html(msg);
},
error: function () {
alert(\'Error\');
}
});
});
});
通过在函数中包含以下代码来添加自定义js文件。php文件:
function add_custom_scripts() {
wp_enqueue_script( \'custom-script\', get_stylesheet_directory_uri() .\'/js/custom-scripts.js\' );
}
add_action( \'wp_enqueue_scripts\', \'add_custom_scripts\' );