Wordpress FAQ手风琴自定义帖子类型 - 匿名功能问题 [英] Wordpress FAQ accordion custom post type - anonymous function issue

查看:57
本文介绍了Wordpress FAQ手风琴自定义帖子类型 - 匿名功能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的wordpress网站中以手风格的方式显示FAQ自定义帖子类型,我在这里找到了如何执行此操作的教程:https://code.tutsplus.com/articles/create-an-faq-accordion- for-wordpress-with-jquery-ui - wp-25706



我在functions.php中添加了所有代码:



/ *注册自定义帖子类型* /



add_action('init',function(){



$ labels = array(

'name'=> _x('FAQ','post type general name'),

'tingular_name '=> _x('问题','发布类型奇异名称'),

'add_new'=> _x('添加新问题','问题'),

'add_new_item'=> __('添加新问题'),

'edit_item'=> __('编辑问题'),

'new_item '=> __('新问题'),

'all_items' => __('所有常见问题解答'),

'view_item'=> __('查看问题'),

'search_items'=> __('搜索常见问题'),

'not_found'=> __('未找到常见问题解答'),

'not_found_in_trash'=> __('在垃圾箱中找不到常见问题'),

'parent_item_colon'=> '',

'menit_name'=> '常见问题'

);



$ args = array(

'labels'=> $ labels ,

'public'=> true,

'publicly_queryable'=> true,

'show_ui'=> true,

'show_in_menu'=> true,

'query_var'=> true,

'重写'=> true,

'能力_类型'=>'发布',

'has_archive'=> true,

'hierarchical'=> false,
't menu_position'=> null,

'支持'=>数组('title','editor','page-attributes')

);

register_post_type('FAQ',$ args);

});



add_action( 'wp_enqueue_scripts','wptuts_enqueue');

函数wptuts_enqueue (){

wp_register_style('wptuts-jquery-ui-style','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/south-street/ jquery-ui.css');

wp_enqueue_style('wptuts-jquery-ui-style');



wp_register_script('wptuts- custom-js',get_template_directory_uri()。 '/faq/faq.js','jquery-ui-accordion','',true);

wp_enqueue_script('wptuts-custom-js');

}



add_shortcode('faq',function(){



$ posts = get_posts(array( //获取常见问题解答自定义帖子类型

'numberposts'=> 10,

'orderby'=>'menu_order',

'order'=>'ASC',

'post_type'=>'faq',

));



$ faq ='

I want to display FAQ custom post type in an accordian style within my wordpress site and I found a tutorial how to do this here: https://code.tutsplus.com/articles/create-an-faq-accordion-for-wordpress-with-jquery-ui--wp-25706

I added all the code in functions.php:

/* Register the Custom Post Type */

add_action('init', function() {

$labels = array(
'name' => _x('FAQ', 'post type general name'),
'singular_name' => _x('Question', 'post type singular name'),
'add_new' => _x('Add New Question', 'Question'),
'add_new_item' => __('Add New Question'),
'edit_item' => __('Edit Question'),
'new_item' => __('New Question'),
'all_items' => __('All FAQ Questions'),
'view_item' => __('View Question'),
'search_items' => __('Search FAQ'),
'not_found' => __('No FAQ found'),
'not_found_in_trash' => __('No FAQ found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'FAQ'
);

$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'page-attributes')
);
register_post_type('FAQ', $args);
});

add_action( 'wp_enqueue_scripts', 'wptuts_enqueue' );
function wptuts_enqueue() {
wp_register_style('wptuts-jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/south-street/jquery-ui.css');
wp_enqueue_style('wptuts-jquery-ui-style');

wp_register_script('wptuts-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true);
wp_enqueue_script('wptuts-custom-js');
}

add_shortcode('faq', function() {

$posts = get_posts(array( //Get the FAQ Custom Post Type
'numberposts' => 10,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'faq',
));

$faq = '

'; //打开容器

foreach($ posts as $ post){//为每个生成标记问题

$ faq。= sprintf(('

%1 $ s

'; //Open the container
foreach ( $posts as $post ) { // Generate the markup for each Question
$faq .= sprintf(('

%1$s

%2 $ s

'),

$ post-> post_title,

wpautop($ post-> post_content)

);

}

$ faq。='

'),
$post->post_title,
wpautop($post->post_content)
);
}
$faq .= '

'; //关闭容器



返回$ faq; //返回HTML。

});



我在faq.js中添加了jquery代码,如下所示:



(function(){

jQuery(#wptuts-accordion)。accordion();

})() ;



我收到错误:



未捕获TypeError:undefined不是functionfaq.js ?ver = 4.1:2(匿名函数)faq.js?ver = 4.1:3(匿名函数)



如何解决这个问题,我做错了什么?我检查了我的托管,我正在使用最新的PHP版本,因为我认为这可能是问题...



谢谢!

'; //Close the container

return $faq; //Return the HTML.
});

And I added jquery code in faq.js like this:

(function(){
jQuery("#wptuts-accordion").accordion();
})();

I'm getting the error:

Uncaught TypeError: undefined is not a functionfaq.js?ver=4.1:2 (anonymous function)faq.js?ver=4.1:3 (anonymous function)

How to fix this, what am I doing wrong? I checked on my hosting, I'm using the latest PHP version, as I thought that may be the issue...

Thanks!

推荐答案

labels = array(

'name'=> _x('FAQ','post type general name'),

'pleular_name'=> _x('问题','发布类型单数名称'),

'add_new'=> _x('添加新问题','问题'),

'add_new_item'=> __('添加新问题'),

'edit_item'=> __('编辑问题'),

'new_item'=> __('新问题'),

'all_items'=> __('所有常见问题解答'),

'view_item'= > __('查看问题'),

'search_items'=> __('搜索常见问题解答'),

'not_found'=> __('否常见问题解答'),

'not_foun d_in_trash'=> __('在垃圾箱中找不到常见问题'),

'harent_item_colon'=>'',

'menit_name'=> '常见问题'

);


labels = array(
'name' => _x('FAQ', 'post type general name'),
'singular_name' => _x('Question', 'post type singular name'),
'add_new' => _x('Add New Question', 'Question'),
'add_new_item' => __('Add New Question'),
'edit_item' => __('Edit Question'),
'new_item' => __('New Question'),
'all_items' => __('All FAQ Questions'),
'view_item' => __('View Question'),
'search_items' => __('Search FAQ'),
'not_found' => __('No FAQ found'),
'not_found_in_trash' => __('No FAQ found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'FAQ'
);


args = array(

'标签'=>
args = array(
'labels' =>


标签,

'public'=> true,

'publicly_queryable'=> true,

'show_ui'=> true,

'show_in_menu'=> true,

'query_var'=> true,

'wtrite'=> true,

'adability_type'=>'post',

'has_archive'=> true,
'hierarchical'=> false,

'menu_position'=> null,

'支持'=>数组('title','编辑','页面属性')

);

register_post_type('FAQ',
labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'page-attributes')
);
register_post_type('FAQ',


这篇关于Wordpress FAQ手风琴自定义帖子类型 - 匿名功能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆