给 WPJobManager 发布工作、单篇工作帖子信息中增加工资字段。

给 WPJobManager 发布工作、单篇工作帖子信息中增加工资字段。


标签: 

正在查看 4 个帖子:1-4 (共 4 个帖子)
  • 作者
    帖子
  • 诗语
    管理员
    • 文章数量: 5,865
    @feibisi
    楼主

    实现的效果如下:

    需要添加段代码到主题的 functions.php 文件中。

    诗语
    管理员
    • 文章数量: 5,865
    @feibisi
    楼主

    先贴上原始代码如下:

    
    // 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>';
    	  }
    }
    

    这样就可以正常显示了。

    诗语
    管理员
    • 文章数量: 5,865
    @feibisi
    楼主

    感兴趣的朋友可以自己预览下效果:

    https://job.weixiaoduo.com/job/604

    诗语
    管理员
    • 文章数量: 5,865
    @feibisi
    楼主
    此回复已被标记为私有,🔒 仅楼主及管理员可见。
正在查看 4 个帖子:1-4 (共 4 个帖子)
  • 哎呀,回复话题必需登录。

未找到对应子版块?请直接在 [疑难杂症] 版块中发帖提问。

收藏纪念品


有奖活动

参与论坛社区问答,有机会获赠文派瓦普(Wapuu.com)手办模型。

话题信息

商业系统