標籤: 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 個帖子)
- 哎呀,回覆話題必需登入。