如何加载Wordpress分类列表并使用Ajax onclick发布

如何加载Wordpress分类列表并使用Ajax onclick发布,wordpress,wordpress-theming,Wordpress,Wordpress Theming,很抱歉读了这么长时间 我希望你们能帮我。我正在尝试显示一个分类列表,该列表将在与主文章页面相同的文章中加载该分类的内容 我一直在看这个脚本,在这个网站上找到() Javascript: jQuery.noConflict(); jQuery(document).ready(function($){ $.ajaxSetup({cache:false}); $("a.ajax").click(function(){ var post_url = $(this).att

很抱歉读了这么长时间

我希望你们能帮我。我正在尝试显示一个分类列表,该列表将在与主文章页面相同的文章中加载该分类的内容

我一直在看这个脚本,在这个网站上找到()

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;
    });
});
jQuery.noConflict();
jQuery(文档).ready(函数($){
$.ajaxSetup({cache:false});
$(“a.ajax”)。单击(函数(){
var post_url=$(this.attr(“href”);
var post_id=$(this.attr(“rel”);
$(“#tabs”).html('loading…');
$(“#制表符”).load(发布url);
返回false;
});
});
我想在其中显示帖子内容的页面(我使用称为“artwork”的自定义帖子类型):

以及“SingleArtwork.php”这篇文章。注意:不要使用get\u页眉或get\u页脚等:

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
  <div class="tabcontent" id="tab-<?php the_ID(); ?>">
    <?php the_content(); ?>
  </div>
<?php endwhile; endif; ?>


好的,我通过使用一个自定义的get\u terms\u list函数来修复它。问题是class=“ajax”没有提供给链接。通过创建一个自定义函数将ajax类提供给链接。文章将在#tabs div中打开

function get_the_term_list_custom( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $id, $taxonomy );

if ( is_wp_error( $terms ) )
    return $terms;

if ( empty( $terms ) )
    return false;

$links = array();

foreach ( $terms as $term ) {
    $link = get_term_link( $term, $taxonomy );
    if ( is_wp_error( $link ) ) {
        return $link;
    }
    $links[] = '<a class="ajax" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}

/**
 * Filter the term links for a given taxonomy.
 *
 * The dynamic portion of the filter name, `$taxonomy`, refers
 * to the taxonomy slug.
 *
 * @since 2.5.0
 *
 * @param array $links An array of term links.
 */
$term_links = apply_filters( "term_links-$taxonomy", $links );

return $before . join( $sep, $term_links ) . $after;
函数获取术语列表自定义($id,$taxonomy,$before='',$sep='',$after=''){
$terms=获取术语($id,$taxonomy);
如果(是错误($terms))
返回$terms;
如果(空($条款))
返回false;
$links=array();
foreach($terms作为$term){
$link=get\u term\u link($term$taxonomy);
如果(是错误($link)){
返回$link;
}
$links[]='';
}
/**
*筛选给定分类法的术语链接。
*
*筛选器名称的动态部分“$taxonomy”引用
*分类学鼻涕虫。
*
*@自2.5.0以来
*
*@param array$links一组术语链接。
*/
$term\u links=apply\u过滤器(“term\u links-$taxonomy”,$links);
返回$before.join($sep,$term\u links)。$after;
}

就这样…我很高兴

<a href="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>" class="ajax"><?php echo get_the_term_list( $post->ID, 'inclusief'); ?></a>
function get_the_term_list_custom( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $id, $taxonomy );

if ( is_wp_error( $terms ) )
    return $terms;

if ( empty( $terms ) )
    return false;

$links = array();

foreach ( $terms as $term ) {
    $link = get_term_link( $term, $taxonomy );
    if ( is_wp_error( $link ) ) {
        return $link;
    }
    $links[] = '<a class="ajax" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}

/**
 * Filter the term links for a given taxonomy.
 *
 * The dynamic portion of the filter name, `$taxonomy`, refers
 * to the taxonomy slug.
 *
 * @since 2.5.0
 *
 * @param array $links An array of term links.
 */
$term_links = apply_filters( "term_links-$taxonomy", $links );

return $before . join( $sep, $term_links ) . $after;