WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
[resolved] display content of a cell (18 posts)

  1. eukally
    Member
    Posted 3 years ago #

    Hello

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

  2. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    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

  3. eukally
    Member
    Posted 3 years ago #

    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

  4. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    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

  5. eukally
    Member
    Posted 3 years ago #

    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

  6. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    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

  7. eukally
    Member
    Posted 3 years ago #

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

    Great! Vielen Dank dir!!!!

  8. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  9. joe.b3
    Member
    Posted 3 years ago #

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

  10. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    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

  11. joe.b3
    Member
    Posted 3 years ago #

    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.

  12. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

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

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

    Regards,
    Tobias

  13. joe.b3
    Member
    Posted 3 years ago #

    That worked! Thanks for your help!

  14. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    no problem, you are welcome!

    Tobias

  15. SKSchouten
    Member
    Posted 2 years ago #

    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!

  16. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    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

  17. malcolm lear
    Member
    Posted 2 years ago #

    Hi Tobias,

    That works!!!! A incredibly useful feature :-) Any chance you could implement this in the plugin for those a little unsure about inserting code?

    Cheers
    Malcolm

  18. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi Malcolm,

    nice to hear that you like the feature! :-)

    I don't think that I'll add the Shortcode to the plugin, as there are not really that many users who need this feature, and the solution with a small plugin works well too.

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic