Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Johann Heyne

    (@jonua)

    Hi,

    in general, it would be possible. But is a simple text input enough for every use case of the caption? The same issue already came up for the cells content. Requests like “caption should be required” or “caption should be Rich Text” are better to solve using an separate ACF field for editing the caption. The only point to include a caption input field option in the table field is to have that option visually bundled width the table field. Is it a good move to add a caption text option? What do you think?

    Cheers,
    Johann

    • This reply was modified 5 years, 5 months ago by Johann Heyne.
    Plugin Author Johann Heyne

    (@jonua)

    Hi,

    you can download the upcomming version 1.3.0 including support for table caption…
    https://downloads.wordpress.org/plugin/advanced-custom-fields-table-field.1.3.0.zip

    The basic template code including caption is…

    
    $table = get_field( 'your_table_field_name' );
    
    if ( $table ) {
    
        echo '<table border="0">';
    
            if ( ! empty( $table['caption'] ) ) {
    
                echo '<caption>' . $table['caption'] . '</caption>';
            }
    
            if ( $table['header'] ) {
    
                echo '<thead>';
    
                    echo '<tr>';
    
                        foreach ( $table['header'] as $th ) {
    
                            echo '<th>';
                                echo $th['c'];
                            echo '</th>';
                        }
    
                    echo '</tr>';
    
                echo '</thead>';
            }
    
            echo '<tbody>';
    
                foreach ( $table['body'] as $tr ) {
    
                    echo '<tr>';
    
                        foreach ( $tr as $td ) {
    
                            echo '<td>';
                                echo $td['c'];
                            echo '</td>';
                        }
    
                    echo '</tr>';
                }
    
            echo '</tbody>';
    
        echo '</table>';
    }
    

    Please test and let me know, if this fits your request.

    Cheers,
    Johann

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Feature Request: Caption’ is closed to new replies.