标签: WPJobManager
正在查看 4 个帖子:1-4 (共 4 个帖子)
-
作者帖子
-
实现的效果如下:
需要添加段代码到主题的 functions.php 文件中。
先贴上原始代码如下:
// Add your own function to filter the fields in admin add_filter( 'job_manager_job_listing_data_fields', 'admin_add_salary_field' ); // Here we create the function for this custom field in admin function admin_add_salary_field( $fields ) { $fields['_job_salary'] = array( 'label' => __( 'Salary ($)', 'job_manager' ), 'type' => 'text', 'placeholder' => 'e.g. 20000', 'description' => '' ); return $fields; } // Add your own function to filter the fields in frontend add_filter( 'submit_job_form_fields', 'frontend_add_salary_field' ); // Here we create the function for this custom field in frontend function frontend_add_salary_field( $fields ) { $fields['job']['job_salary'] = array( 'label' => __( 'Salary ($)', 'job_manager' ), 'type' => 'text', 'required' => true, 'placeholder' => 'e.g. 20000', 'priority' => 7 ); return $fields; } // Add your salary field to display on single job page add_action( 'single_job_listing_meta_end', 'display_job_salary_data' ); // Here we create the function for this custom field to display on single job page function display_job_salary_data() { global $post; $salary = get_post_meta( $post->ID, '_job_salary', true ); if ( $salary ) { echo '<li>' . __( 'Salary:' ) . ' $' . esc_html( $salary ) . '</li>'; } }
为了适应国内的环境,和本地化要修改几个字符串和小地方。
修改后如下:
// Add your own function to filter the fields in admin add_filter( 'job_manager_job_listing_data_fields', 'admin_add_salary_field' ); // Here we create the function for this custom field in admin function admin_add_salary_field( $fields ) { $fields['_job_salary'] = array( 'label' => __( ' 工资 (¥)', 'job_manager' ), 'type' => 'text', 'placeholder' => 'e.g. 20000', 'description' => '' ); return $fields; } // Add your own function to filter the fields in frontend add_filter( 'submit_job_form_fields', 'frontend_add_salary_field' ); // Here we create the function for this custom field in frontend function frontend_add_salary_field( $fields ) { $fields['job']['job_salary'] = array( 'label' => __( ' 工资 (¥)', 'job_manager' ), 'type' => 'text', 'required' => true, 'placeholder' => 'e.g. 20000', 'priority' => 7 ); return $fields; } // Add your salary field to display on single job page add_action( 'single_job_listing_meta_end', 'display_job_salary_data' ); // Here we create the function for this custom field to display on single job page function display_job_salary_data() { global $post; $salary = get_post_meta( $post->ID, '_job_salary', true ); if ( $salary ) { echo '<li class="salary" >' . __( ' 工资:' ) . ' ¥' . esc_html( $salary ) . '</li>'; } }
这样就可以正常显示了。
此回复已被标记为私有,🔒 仅楼主及管理员可见。 -
作者帖子
正在查看 4 个帖子:1-4 (共 4 个帖子)
- 哎呀,回复话题必需登录。