Forum Replies Created

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter silvios

    (@silvios)

    I think you missed my last reply could you please take a look?

    i think that the fix should really allow us to define our own api key somewhere, in a file or in a setting, and maybe default to your key, but in the end each user should be using their own key

    Thread Starter silvios

    (@silvios)

    I just took a look at the newest version thank you very much for taking the time to make the changes. I see you added filters but they are not being applied. From what I can tell they are just adding filters to the filter stack.

    In order for me to actually hook into them you need to use the “apply_filters” function.

    This is sample code that is in my plugin.

    add_filter('sgr-nextpage-next-page-filter', 'sgr_next_page_filter', 10, 2);
    
    function sgr_next_page_filter($html, $sgrObj)
    {
        global $post;
    
        $subpages = $post->post_subpages;
    
        //current page
        $page = ( get_query_var('page') ) ? get_query_var('page') : 1;
    
        $back = '<a href="' . $sgrObj->get_subpage_link( $page - 1 ) . '"><div class="multipage-navlink" style="width:20%;float:left;">' . __( 'Back', 'sgr-npt' ) . '</div></a>';
        $next = '<a href="' . $sgrObj->get_subpage_link( $page +1 ) . '">' . '<div class="multipage-navlink" style="width:65%;float:right;">' . __( 'Next:', 'sgr-npt' ) . $subpages[ $page ] .'<i class="fa fa-arrow-right" style="margin-left:10px; vertical-align:middle;"></i></div></a>';
    
        return '<div class="nav-containers">' . $back . $next . "</div>";
    }

    In the file sgr-nextpage-titles.php currently after the block line 268-272

    if ( $page === count( $subpages ) ) {
    			$multipagenav = '<div class="multipage-navlink">' . __( 'Back to: ', 'sgr-npt' ) . ' <a href="' . get_permalink() . '">' . $subpages[ 0 ] . '</a></div>';
    		} else {
    			$multipagenav = '<div class="multipage-navlink">' . __( 'Continue:', 'sgr-npt' ) . ' <a href="' . $this->get_subpage_link( $page +1 ) . '">' . $subpages[ $page ] .'</a></div>';
    		}

    I want to add an apply_filters method which allows me to use the add_filter method to add changes to the navigation html like this:

    $multipagenav = apply_filters( 'sgr-nextpage-next-page-filter', $multipagenav, $this );

    I personally want to create my own navigation html completely. Does that make any sense? In my example function i will just completely change the output into something different.

    So you can simply change line 268 to 272 of sgr-nextpage-titles.php into something like

    if ( $page === count( $subpages ) ) {
    			$multipagenav = '<div class="multipage-navlink">' . __( 'Back to: ', 'sgr-npt' ) . ' <a href="' . get_permalink() . '">' . $subpages[ 0 ] . '</a></div>';
    		} else {
    			$multipagenav = '<div class="multipage-navlink">' . __( 'Continue:', 'sgr-npt' ) . ' <a href="' . $this->get_subpage_link( $page +1 ) . '">' . $subpages[ $page ] .'</a></div>';
    		}
    $multipagenav = apply_filters( 'sgr-nextpage-next-page-filter', $multipagenav, $this );
    Thread Starter silvios

    (@silvios)

    Hey, I have not checked the source, but in the change log I did not see mention of any of the changes we discussed. Does that mean you have not had a chance to release the newest version? I just want to ensure your new changes and my changes will work well together.

    If you have already released the changes with the newest version my apologizes, but please do let me know.

    Thanks 🙂

    Thread Starter silvios

    (@silvios)

    perfect thanks

    Thread Starter silvios

    (@silvios)

    One other issue, I was running into, when using the relevanssi plugin in combination with your plugin, and using the nav filters, the native wordpress shortcode’s would not be processed, the solution is to add your ‘the_content’ filter at at the lowest priority so it runs last, in the end it really should always run last anyway in order to add nav buttons at the bottom of the content, just change line

    137

    add_filter( 'the_content', 			array( &$this, 'enhance_content' ) );

    to

    add_filter( 'the_content', 			array( &$this, 'enhance_content' ), 20 );
    Thread Starter silvios

    (@silvios)

    i just discovered this method “is_main_query” this checks to see if the query is the main one, which means we probably want to check that as well.

    if (!is_main_query() || !property_exists($post, 'post_subpages'))
               return $content;

    rather than

    if ( !property_exists($post, 'post_subpages'))
               return $content;

    Thread Starter silvios

    (@silvios)

    sounds good, when should I expect this to be released? Just so I can update my current code to ensure we are on the same page, otherwise if I forgot to update my code when we update your code it will break mine lol

    Thread Starter silvios

    (@silvios)

    One other very minor issue, in the function enhance_content in the file sgr-nextpage-title.php we should also add

    if (!property_exists($post, 'post_subpages'))
               return $content;

    after the line

    if ( ! is_singular() )
    			return $content;

    in some cases where the post is not the ‘main’ post being viewed in the single page, it will throw a notice. I did not look too deeply into it, but you can replicate it by creating a new WP_Posts object and just getting the excerpt. Although the notice doesn’t really cause and major issues from what I could see, its always worth fixing, and saves processing power. Let me know if you have any questions, or concerns

    Thread Starter silvios

    (@silvios)

    Here is a proper example:
    This is a filter I would use (an example):

    add_filter('sgr-nextpage-next-page-filter', 'sgr_next_page_filter', 10, 2);
    
    function sgr_next_page_filter($html, $sgrObj)
    {
        global $post;
    
        $subpages = $post->post_subpages;
    
        //current page
        $page = ( get_query_var('page') ) ? get_query_var('page') : 1;
    
        $back = '<a href="' . $sgrObj->get_subpage_link( $page - 1 ) . '"><div class="multipage-navlink" style="width:20%;float:left;">' . __( 'Back', 'sgr-npt' ) . '</div></a>';
        $next = '<a href="' . $sgrObj->get_subpage_link( $page +1 ) . '">' . '<div class="multipage-navlink" style="width:65%;float:right;">' . __( 'Next:', 'sgr-npt' ) . $subpages[ $page ] .'<i class="fa fa-arrow-right" style="margin-left:10px; vertical-align:middle;"></i></div></a>';
    
        return '<div class="nav-containers">' . $back . $next . "</div>";
    }

    we would add the filter right after :

    if ( $page === count( $subpages ) ) {
                $multipagenav = '<div class="multipage-navlink">' . __( 'Back to: ', 'sgr-npt' ) . ' <a href="' . get_permalink() . '">' . $subpages[ 0 ] . '</a></div>';
    		} else {
    			$multipagenav = '<div class="multipage-navlink">' . __( 'Next:', 'sgr-npt' ) . ' <a href="' . $this->get_subpage_link( $page +1 ) . '">' . $subpages[ $page ] .'</a><i class="fa fa-arrow-right" style="margin-left:10px; vertical-align:middle;"></i></div>';
    		}
    
            $multipagenav = apply_filters( 'sgr-nextpage-next-page-filter', $multipagenav, $this );

    We also need to make the method “get_subpage_link” in Nextpage_Titles_Loader public, you might want to make the “get_subpage_title” methods public as well.

    This allows your plugin to be used for the masses and allows users to be able to extend the next page output into something else if they wish.

    Thread Starter silvios

    (@silvios)

    I think maybe the best solution would actually be to just add filters to the next and back links, i think it will be easiest if i write an example and send it over to you.

    I will post one here shortly

    Thread Starter silvios

    (@silvios)

    Ya a filter makes sense. The plugin is not posted publicly. Basically what it does is allows the user to continue to another post rather than going back.

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