給 WPJobManager 釋出工作、單篇工作帖子資訊中增加工資欄位。

標籤: 

正在檢視 4 個帖子:1-4 (共 4 個帖子)
  • 作者
    帖子
  • 詩語
    管理員
    • 文章數量: 5,932
    @feibisi
    樓主

    實現的效果如下:

    需要新增段程式碼到主題的 functions.php 檔案中。

    詩語
    管理員
    • 文章數量: 5,932
    @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,932
    @feibisi
    樓主

    感興趣的朋友可以自己預覽下效果:

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

    詩語
    管理員
    • 文章數量: 5,932
    @feibisi
    樓主
    此回覆已被標記為私有,🔒 僅樓主及管理員可見。
正在檢視 4 個帖子:1-4 (共 4 個帖子)
  • 哎呀,回覆話題必需登入。

話題資訊

  • 當前位於:WP Job Manager
  • 3 條回覆
  • 1 個參與人
  • 最後回覆:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 檢視詩語的個人資料" class="bbp-author-link"><span class="bbp-author-name"> 詩語</span></a>
  • 上次活動:<a href="https://bbs.weixiaoduo.com/topic/22248/#post-27011" title=" 回覆至:給 WPJobManager 釋出工作、單篇工作帖子資訊中增加工資欄位。">6 年、 9 月前</a>