• Resolved eukally

    (@eukally)


    Hello

    is it possible to display i a post only the content of a certain cell of a table (with a shortcode)?

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

    (@tobiasbg)

    Hi,

    you are lucky, I found the email in which I had mailed the necessary code to someone over a year ago πŸ™‚

    Here is the code:

    <?php
    
    // handle [table_data id=123 c=4 r=5 /]
    function shortcode_handler_table_data( $atts ) {
      global $WP_Table_Reloaded_Frontend;  
    
      $atts = shortcode_atts( array( 'id' => 0, 'c' => 0, 'r' => 0 ), $atts );
      $table_id = $atts['id'];
      $column = $atts['c'] - 1; // subtract 1 because of different array index
      $row = $atts['r'] - 1; // subtract 1 because of different array index
    
      $table = $WP_Table_Reloaded_Frontend->load_table( $table_id );
      $cell_content = $table['data'][$row][$column];
      return do_shortcode( $WP_Table_Reloaded_Frontend->helper->safe_output( $cell_content ) );
    }
    add_shortcode( 'table_cell', 'shortcode_handler_table_data' );
    ?>

    If you copy this code (you probably don’t need the <?php and ?>) into your theme’s “functions.php”, you will have a new shortcode, like this:

    [table_cell id=123 c=4 r=5 /]

    This will return the content (and just the content) of row 5, column 4 of table 123. (I shortened the parameters to “c” and “r”, to have smaller shortcodes. And I did not include any checks though, if the table/row/column really exist, so in those cases you will get a PHP parse error.)

    This should be what you want though πŸ™‚

    Best wishes,
    Tobias

    Thread Starter eukally

    (@eukally)

    looks nice, but I am getting an error:
    Fatal error: Call to undefined method WP_Table_Reloaded_Controller_Frontend::safe_output() in /mnt/weba/63/26/5932326/htdocs/wp/wp-content/themes/standard/functions.php on line 240

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ah, my bad, sorry. The code needs a slight change, as WP-Table Reloaded got a slight change during that year since the code was needed πŸ™‚

    Please try again, I updated the code in the post above (still not tested though).

    Regards,
    Tobias

    Thread Starter eukally

    (@eukally)

    no not yet:

    Fatal error: Call to a member function safe_output() on a non-object in /mnt/weba/63/26/5932326/htdocs/wp/wp-content/themes/standard/functions.php on line 239

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    argh, turns out to be a little bit more tricky πŸ™‚

    Can you try again with this new code (I can’t edit the post above, as it is now too old)? (Unfortunately, I can’t test the code right now, so I’ll have to ask you to do it…)

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Regards,
    Tobias

    Thread Starter eukally

    (@eukally)

    Tobias – that was it its great – und sogar Links funktionieren auf diese Weise –

    Great! Vielen Dank dir!!!!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    awesome, thanks for the confirmation! πŸ™‚

    Best wishes,
    Tobias

    P.S.: Dear Forums moderator: I understand and totally agree that pasting large amounts of code here is not desirable, but we are talking about 17 small rows here… In fact, if I were allowed to edit my old post from above, I would not even had the need to post it twice.

    Could I get a copy of the working code as well? It has been removed from your post.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sure. Please take the code from my first answer and replace the line

    return do_shortcode( $WP_Table_Reloaded_Frontend->helper->safe_output( $cell_content ) );

    with

    $render = $WP_Table_Reloaded_Frontend->create_class_instance( 'WP_Table_Reloaded_Render', 'render.class.php' );
    return do_shortcode( $render->helper->safe_output( $cell_content ) );

    Best wishes,
    Tobias

    Thanks. After replacing the line of code with the two you posted, though, I get the “Call to a member function safe_output() on a non-object” error that eukally did when I try to use the shortcode.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    oh, my bad again. Similar mistake as in my first post, sorry…

    Please remove the helper-> in the second new line.

    Regards,
    Tobias

    That worked! Thanks for your help!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are welcome!

    Tobias

    Hello,

    I tried the code above but it’s not returning the content of the actual cell… Though I don’t get any PHP errors either. Did the code happen to change again or should it still be working? I’m pretty bad at PHP, so it would be very possible that it’s just me.

    Also, is this code meant to display any cell (using the right shortcode of course), or is this code only to get [table_cell id=123 c=4 r=5 /] to work?

    Thanks so much for your help in advance!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no that code can be used to get any cell from any table not just cell 4/5 from table 123, that’s just an example.

    Did you follow all of my posts in this thread and apply all the modifications? There are some, so that he plain code from the first answer alone won’t work.

    And have you added the code to the currently activated theme’s functions.php? Or in a different location?

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Plugin: WP-Table Reloaded] display content of a cell’ is closed to new replies.