WordPress.org

Ready to get started?Download WordPress

Forums

Simple Paginated Posts
Match by heading not shortcode (2 posts)

  1. smartredfox
    Member
    Posted 9 months ago #

    Hello,

    Thanks for the plugin - it's a real time saver!

    I'm not sure if this is any help for you at all but I needed to adapt the plugin so that users don't have to enter the shortcodes after the nextpage tags (believe it or not this is too complex for our users). So I changed your for loop in /includes/class-simple-paginated-posts.php on line 276 to get the first heading in the html block of each page as a title. I also added a check to make sure it gets a heading (or shortcode) and if not fill it with a default (Page 1, Page 2 etc.). The code is:

    for ( $i = 1; $i < ($numpages); $i = $i + 1 ) {
                    //Match headings
                    preg_match('|<h[^>]+>(.*)</h[^>]+>|iU',$pages[$i],$matchingHeadings[$i]);  
    
                    //If we found a match use it as our heading
                    if(!empty($matchingHeadings[$i])){
                        //TODO:Strip out any innerhtml that may be there (spans, links etc.)
                        $this->page_titles[] = trim($matchingHeadings[$i][1]);//1 is the inner part
                    }
                    else{
                        preg_replace_callback( "/$shortcode_pattern/s", array( $this, 'get_shortcode_atts' ), $pages[$i] );
                    }
    
                    //No title found use default
                    if(empty($this->page_titles[$i])){
                        $this->page_titles[] = __('Page ') . ($i + 1);
                    }
    			}

    I'd love to see this added into the plugin if possible.

    Thanks,
    James

    http://wordpress.org/extend/plugins/simple-paginated-posts/

  2. smartredfox
    Member
    Posted 9 months ago #

    Hello,

    Me again. I've spotted and fixed a bug where it looks like the auto/manual option wasn't saving on the settings page.

    When the settings page saves it overwrites the tla_spp_options setting in the database that holds the version number. This means that the version number always shows as 0 after save, which then makes the version check code fire and update the auto/manual as auto again!

    Adding the version number in as a hidden field fixes this (added in /includes/class-spp-admin.php on line 145):

    echo "<input type='hidden' name='tla_spp_options[version]' value='" . $options['version'] . "'>";

    Thanks again,
    James

Reply

You must log in to post.

About this Plugin

About this Topic