• Resolved tcabrera

    (@tcabrera)


    Love love love this plugin! Will definitely make a donation.

    I wanted to check…

    Is it possible to have a feature on certain tables (not all) to have the sequence of rows appear random everytime the page reloads?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    you can actually achieve something like that by some custom programming.
    You would need to hook into the filter wp_table_reloaded_render_table, which gets passed the table data, before it is rendered. There, you would just need to do the randomization, which is easy with the corresponding PHP function. All that would need to be put together in a small piece of code, actually a small WordPress plugin.

    Best wishes,
    Tobias

    Thread Starter tcabrera

    (@tcabrera)

    Thanks so much for your reply.

    I’m no programmer so I’d be willing to “donate” more for you to make me one!

    Just give me a quote!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    here’s some code that should do the trick for you.
    Just paste that into your theme’s “functions.php” file (or into a new “WP-Table Reloaded Extension”, as described on my website, and eventually adjust the list of tables that you want randomized (line 2 of the code).

    function wp_table_reloaded_shuffle_table( $table, $orig_table, $this->output_options ) {
        $list_of_random_tables = array( 2, 4, 5, ); // table IDs
    
        if ( ! in_array( $table['id'], $list_of_random_tables ) )
            return $table;
    
        $array_to_shuffle = $table['data'];
        if ( $this->output_options['first_row_th'] )
            $first_row = array_shift( $array_to_shuffle );
        if ( $this->output_options['table_footer'] )
            $last_row = array_pop( $array_to_shuffle );
    
        shuffle( $array_to_shuffle );
    
        if ( $this->output_options['first_row_th'] )
            array_unshift( $array_to_shuffle, $first_row );
        if ( $this->output_options['table_footer'] )
            array_push( $array_to_shuffle, $last_row );
    
        $table['data'] = $array_to_shuffle;
    
        return $table;
    }
    add_filter( 'wp_table_reloaded_render_table', 'wp_table_reloaded_shuffle_table', 10, 3 );

    I also added some checks for features like “Table Head” and “Table Footer”, which should not get shuffled. Note, that I did not test the code, but it should work like this.

    All in all, it took me half an hour of research and coding, so whatever “value” you give to this is fine for me 🙂

    Best wishes,
    Tobias

    Thread Starter tcabrera

    (@tcabrera)

    Thanks again for taking the time to do this.

    You should have seen a donation come through under tony_cabrera via paypal.

    I plan on adding to that once I can get this working.

    So I’ve done everything on your extension instructions. But when I try to activate the plugin, it gives me this error on basically the first line of the extension code (on line 12 of the file below).

    “Parse error: syntax error, unexpected T_FUNCTION”

    I’ve tried looking at your 7 examples to see if I can compare figure out what’s causing the error, but no luck.

    Here’s what I have on the php file. (without the dashes of course)

    —————————————————————–
    <?php
    /*
    Plugin Name: WP-Table Reloaded Extensions
    Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded-english/extensions/
    Description: Custom Extensions for WP-Table Reloaded
    Version: 1.0
    Author: YOU, Tobias Baethge
    */
     
    // this is where the actual code goes

    function wp_table_reloaded_shuffle_table( $table, $orig_table, $this->output_options )
    {
    $list_of_random_tables = array( 2, 4, 5, ); // table IDs

    if ( ! in_array( $table[‘id’], $list_of_random_tables ) )
    return $table;

    $array_to_shuffle = $table[‘data’];
    if ( $this->output_options[‘first_row_th’] )
    $first_row = array_shift( $array_to_shuffle );
    if ( $this->output_options[‘table_footer’] )
    $last_row = array_pop( $array_to_shuffle );

    shuffle( $array_to_shuffle );

    if ( $this->output_options[‘first_row_th’] )
    array_unshift( $array_to_shuffle, $first_row );
    if ( $this->output_options[‘table_footer’] )
    array_push( $array_to_shuffle, $last_row );

    $table[‘data’] = $array_to_shuffle;

    return $table;
    }
    add_filter( ‘wp_table_reloaded_render_table’, ‘wp_table_reloaded_shuffle_table’, 10, 3 );
     
    ?>
    —————————————————————–

    Thread Starter tcabrera

    (@tcabrera)

    Update –

    I tried to edit the file within WordPress editor to see if my FTP is screwing with the file when transferred.

    Now I’m getting a different error message when I try to activate the plugin. I’m getting this:

    “Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ‘)'”

    I’m running on PHP5.

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi Tony,

    yes, I received your donation, thank you very much! I really appreciate it!

    Regarding the error: Whoops, my bad sorry. 🙂 I forgot to rename a variable after copying&pasting a line…

    Here’s the corrected code (as I can’t edit the previous post with the code):

    function wp_table_reloaded_shuffle_table( $table, $orig_table, $output_options ) {
        $list_of_random_tables = array( 2, 4, 5 ); // table IDs
    
        if ( ! in_array( $table['id'], $list_of_random_tables ) )
            return $table;
    
        $array_to_shuffle = $table['data'];
        if ( $output_options['first_row_th'] )
            $first_row = array_shift( $array_to_shuffle );
        if ( $output_options['table_footer'] )
            $last_row = array_pop( $array_to_shuffle );
    
        shuffle( $array_to_shuffle );
    
        if ( $output_options['first_row_th'] )
            array_unshift( $array_to_shuffle, $first_row );
        if ( $output_options['table_footer'] )
            array_push( $array_to_shuffle, $last_row );
    
        $table['data'] = $array_to_shuffle;
    
        return $table;
    }
    add_filter( 'wp_table_reloaded_render_table', 'wp_table_reloaded_shuffle_table', 10, 3 );

    Best wishes,
    Tobias

    Thread Starter tcabrera

    (@tcabrera)

    Awesome! The randomizer works great! And thanks agian for the fast response.

    One more thing though, and I’m not sure if this is a big deal. But I want to make sure it’s not messing with any SEO coding on any page/post.

    Whenever I update or create a page/post/plugin, I get this message in a blank white page. If it’s not a big deal, I can live with it.

    “Warning: Cannot modify header information – headers already sent by (output started at /home1/lifeonpr/public_html/chicagoweddingvenues/main/wp-content/plugins/wp-table-reloaded-extensions.php:37) in /home1/lifeonpr/public_html/chicagoweddingvenues/main/wp-includes/pluggable.php on line 890”

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    great to hear that it works 🙂

    The new error likely means that there is some whitespace in the plugin file.
    That means: You must not have any whitespace or new lines in front of the <?php or after the ?> tag.
    Otherwise that whitespace gets printed to the page, which results in that error.

    Can you check that?

    Regards,
    Tobias

    Thread Starter tcabrera

    (@tcabrera)

    Effen beautiful! That did the trick!

    Awesome awesome awesome!

    Not sure if this is useful for others, but it’s just what I need. If you want to see it in action, it’s here.
    http://www.chicagoweddingvenues.com/main/?page_id=956

    Thanks again for being patient and such a huge help!

    Thanks for your response Tobias, I’m doing something wrong, I get the following error:

    Fatal error: Call to undefined function add_filter() in …wp-includes/functions.php on line 4322

    Any idea what I’m doing wrong?

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    that is the wrong “functions.php” file!

    You must use the “functions.php” file that is in your theme’s folder (if there is none, just create it, and don’t forget the PHP brackets).
    You must not use the “functions.php” in the “wp-includes” folder!

    Best wishes,
    Tobias

    Thanks Tobias!

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘[Plugin: WP-Table Reloaded] Random Row Option’ is closed to new replies.