• Resolved nicolaslienhard

    (@nicolaslienhard)


    Hello
    Is it possible to link a value of a cell (for example a name) with the hyperlink from another cell of the same row in a simple way?
    On my website I want to display a list with the names of artists who are linked to their website/Instagram account. (At the moment, I create the list manually at villekulla.ch/archive/) It is also conceivable that the link next to the name can be accessed via an icon or something like “web”.
    I hope someone will take on this little challenge and help me (I’m a layman when it comes to php or javascript) to solve this problem.

    looking forward to your answers
    nicolas

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I’m a bit confused here. On the page from your link, you are showing a list of artists, either with a link or without. I don’t see a table though?
    Would you just want to have a table as the data storage (e.g. one column for the artist name and one for the URL of the link), but still have a list shown as right now?

    Regards,
    Tobias

    Thread Starter nicolaslienhard

    (@nicolaslienhard)

    Helo,

    and thank you for the fast answer. If i could choose, i’d choose a list, because when it comes to html, it’s a little bit simpler. But the closest i could find to display data from a table was tablepress (if you know a plug in that displays data in a list please let me know) anyway technically, i thought, i can also display my list in a table. CSS will make it look something alike.

    in fact it is not important (to me) how the list is constituted. It would just be neat to just have to import the new table (or the new part or whatever) and the list is automatically updated, complete with the hyperlinks.

    As mentioned above, if an other tool pops in your mind, that suits better my task, let me know

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the clarification!

    Here could be a quick PHP solution. Just add this to the end your theme’s “functions.php” file.

    add_filter( 'tablepress_table_raw_render_data', 'nicolaslienhard_artist_list', 10, 2 );
    function nicolaslienhard_artist_list( $table, $render_options ) {
      if ( '123' !== $table['id'] ) {
        return $table;
      }
      
      foreach ( $table['data'] as $row_idx => $row ) {
          $new_content = $row[0];
          if ( 0 === stripos( $row[1], 'http' ) ) {
            $new_content = "<a href=\"{$row[1]}\">{$new_content}</a>;
          }
          if ( '' !== $row[2] ) {
            $new_content .= " {$row[2]}";
          }
          $table['data'][ $row_idx ][ 0 ] = $new_content;
        }
    
      return $table;
    }

    Make sure to change the 123 in the third line to the table ID of the table that you are using.
    The table should be a column with three column: Column 1 should be just the artist name. Column 2 should be the URL that you want to link to (or left empty). And column 3 can be extra info (like that “(PW: …)” text after one of the artists.
    The code will then automatically turn the first column into a clickable link (if a URL is set) and it will add the text from column 3.
    In addition, you should then mark column 2 and 3 as “hidden” on the table’s “Edit” screen, by clicking the checkboxes below them and clicking the “Selected columns: Hide” button.

    Regards,
    Tobias

    Thread Starter nicolaslienhard

    (@nicolaslienhard)

    yeah great, i can’t wait to try that out! now i have a little papa time, that’s why i can’t dig in right away… I will get back to you

    Thread Starter nicolaslienhard

    (@nicolaslienhard)

    Hmm… the editor says: syntax error, unexpected ‘{‘ on line 13
    $new_content .= " {$row[2]}";
    I tried out different writings but wasn’t lucky

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, my bad. The line a little bit higher is missing a " towards the end:

    $new_content = "<a href=\"{$row[1]}\">{$new_content}</a>";
    

    Regards,
    Tobias

    Thread Starter nicolaslienhard

    (@nicolaslienhard)

    yeah that worked! i’ll have to figure out some details before i put it online but i guess i’ll manage it fron here. thanks a lot!
    nicolas

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias
    ?
    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘link the value of a cell with a hyperlink from another cell’ is closed to new replies.