Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author ka2

    (@ka2)

    Yes, you can.

    The following documents will be a good sample.

    https://ka2.org/cdbt/v2/tutorial/#customize-shortcode

    For example, if the “image_url” column in the “sample” table is stored url of image, it’s as following:

    function my_shortcode_custom_columns( $columns, $shortcode_name, $table ) {
      if ( 'sample' === $table ) {
        foreach ( $columns as $_i => $_column ) {
          $_custom_column = '';
          switch( $_column['property'] ) {
            case 'image_url':
              // Add an image tag with link
              $_custom_column = 'rowData.image_url != "" ? $("<a/>").attr("href",_.unescape(rowData.image_url)).attr("target","_blank").html("<img src=\""+_.unescape(rowData.image_url)+"\">") : "-"';
              break;
          }
          if ( ! empty( $_custom_column ) )
            $columns[$_i]['customColumnRenderer'] = $_custom_column;
        }
      }
      return $columns;
    }
    add_filter( 'cdbt_shortcode_custom_columns', 'my_shortcode_custom_columns', 10, 3 );

    please refer above code and try it.

    Thank you,

    Thread Starter shadowgr

    (@shadowgr)

    Book image

    There is way to do it as below;

    switch( $_column['property'] ) {
            case 'league':
              // Add an image tag with link
    
              $_custom_column = 'rowData.league_url != "" ? $("<a/>").attr("href",_.unescape(rowData.league_url)).attr("target","_blank").text(_.unescape(rowData.league)) : rowData.league';
              break;
              case 'match':
              // Add an image tag with link
    
              $_custom_column = 'rowData.match_url != "" ? $("<a/>").attr("href",_.unescape(rowData.match_url)).attr("target","_blank").text(_.unescape(rowData.match)) : rowData.match';
              break;
    
              case 'book':
    Plugin Author ka2

    (@ka2)

    If the image and the URL is stored in separate columns, please try as following.

    foreach ( $columns as $_i => $_column ) {
      $_custom_column = '';
      switch( $_column['property'] ) {
        case 'book':
          $_custom_column = 'rowData.book_url != "" ? $("<a/>").attr("href",_.unescape(rowData.book_url)).attr("target","_blank").css({display:"block",textAlign:"center"}).html("<img src=\""+_.unescape(rowData.book)+"\" height=\"150\">") : rowData.book';
          break;
        case 'book_url':
          unset( $columns[$_i] );
          break;
      }
      if ( ! empty( $_custom_column ) )
        $columns[$_i]['customColumnRenderer'] = $_custom_column;
    }
    $columns = array_values( $columns );

    Thank you,

    Thread Starter shadowgr

    (@shadowgr)

    thank you ??

    Plugin Author ka2

    (@ka2)

    I closed this issue because that has resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Column Image Link’ is closed to new replies.