【发布时间】:2015-12-14 09:27:45
【问题描述】:
抱歉读了这么久……
我希望你们能帮助我。我试图显示一个分类列表,该列表将在与主帖子页面相同的帖子中加载该分类的内容。
我一直在看这个脚本,在这个网站 (How to load Wordpress Post with Ajax onclick) 上找到。
Javascript:
jQuery.noConflict();
jQuery(document).ready(function($){
$.ajaxSetup({cache:false});
$("a.ajax").click(function(){
var post_url = $(this).attr("href");
var post_id = $(this).attr("rel");
$("#tabs").html('<div class="loading">loading...</div>');
$("#tabs").load(post_url);
return false;
});
});
我要显示帖子内容的页面(我正在使用称为“艺术品”的自定义帖子类型:
<ul class="container">
<?php query_posts('post_type=artwork&posts_per_page=-1'); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<li class="mytab">
<h3><?php the_title(); ?></h3>
<a href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>" class="ajax"><?php the_post_thumbnail('Project'); ?></a>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>
<!-- LOAD SINGLE POST CONTENT IN #TABS -->
<div id="tabs"></div>
还有单篇文章“single-artwork.php”。注意:不要使用 get_header 或 get_footer 等:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div class="tabcontent" id="tab-<?php the_ID(); ?>">
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
我没有使用脚本的最后一部分,因为我已经在 single-{slug}.php 中工作了
这实际上是在同一个窗口中打开分类内容,就像我想要的那样。但这会将缩略图显示为链接。
我真正想要的是只有分类列表,然后打开并显示#tabs div中的内容。
到目前为止,我得到了这个:
<a href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>" class="ajax"><?php echo get_the_term_list( $post->ID, 'inclusief'); ?></a>
它显示了我想要的分类列表。但这会在新页面上打开该分类的内容,而不是在#tabs 中。这是怎么回事……为什么。当然,我怎样才能让这个分类内容在#tabs div中打开......
谢谢!
【问题讨论】:
标签: wordpress wordpress-theming