• Resolved FREEZhao

    (@freezhao)


    I add desiger to the project, sometimes one porject have 2 or more desigers. So I need to show the designer info by 2 conditions:

    A: 1 designer only, then it show “Deisgner: John”

    B:more than 2 designers, then it need to show “Designers: John, Mike, Merry”

    Is there any magic tag or code can do that?

    Thanks for any help~

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @freezhao

    Sure thing, simple example:

    $total = count( $YOUR_RELATIONSHIPS_VARIABLE );
    if ( 1 < count( $total ) ) {
      // Echo multiple
    } else {
      // Echo single
    } 

    Cheers, Jory

    Thread Starter FREEZhao

    (@freezhao)

    Hi @keraweb

    Thanks for your reply, Can you explain more how can use the code, where should I put it in?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @freezhao

    This is PHP code which would go inside a function within your theme or plugin.
    You can then use it as a filter:

    Add to a plugin or functions.php:

    function my_designers_prefix_function( $relationships, $pods ) {
        $total = count( $relationships );
        $display = $pods->display( 'YOUR_FIELD_NAME' );
        if ( 1 < count( $total ) ) {
          return __( 'Designers', 'YOUR DOMAIN' ) . ': ' . $display;
        }
        return __( 'Designer', 'YOUR DOMAIN' ) . ': ' . $display;
    }

    And in your Pods template:

    {@YOUR_FIELD_NAME|my_designers_prefix_function}

    Cheers, Jory

    Plugin Author Jory Hogeveen

    (@keraweb)

    Missed a filter here, you also need to add the following alongside this helper function:

    add_filter( 'pods_helper_include_obj', '__return_true' );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can if condition can separate the plural name?’ is closed to new replies.