Support » Plugins and Hacks » [Resolved] Choose table to display in theme template using custom fields

[Resolved] Choose table to display in theme template using custom fields

  • I would like to display a different table in the sidebar for each post. Is there a way to place the table code in the template and specify a custom field to choose the table to be shown?

    I know I can add the table for each post but I want to use the sidebar because it would be less likely to break the theme. I need to float the table to the right of the content.


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



    thanks for your question.

    Yes, there are “Template Tag” functions that you can use anywhere in the theme. For more information on these, please take a look at the corresponding section in the documentation at http://tablepress.org/documentation/
    You could then combine that with some PHP code that retrieves the value of a custom field and inserts that as the table ID into the Template Tag function.

    Another idea would be to use a plugin like Widget Logic from http://wordpress.org/extend/plugins/widget-logic/ which allows you to show a different text widget on different posts/pages. You could then have different text widgets with a different table Shortcode each.


    Hi Tobias,

    Thanks for the quick response! The first option looks a little daunting with my limited knowledge of PHP. The widget looks like a promising solution but I read that anyone with access to it can possibly add malicious code. Since I would have multiple contributors who need to be able to add the table in this way, it is a likely vulnerability that I would rather not risk.

    The main obstacle is combining the table template tag with the custom function code.

    get_post_meta($post->ID, 'key', true);

    tablepress_print_table( array( 'id' => '1', 'use_datatables' => true, 'print_name' => false ) )

    Plugin Author TobiasBg



    yes, the first option would require some small PHP code in the sidebar area of the theme, while the second method would indeed open the possibility of entering malicious PHP code.

    However, for the first option, combining the custom field with the Template Tag function is not that difficult:

    $table_id = get_post_meta( $post->ID, 'sidebar_tablepress_table_id', true );
    if ( ! empty( $table_id ) )
      tablepress_print_table( array( 'id' => $table_id ) );

    With that, you would just have to add a custom field named sidebar_tablepress_table_id to the post.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Choose table to display in theme template using custom fields’ is closed to new replies.