Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter grizzam

    (@grizzam)

    Good find! Where does this script go in the file directory? Does it go in the root of the wordpress-seo folder, within a subfolder, appended to file?…

    Thread Starter grizzam

    (@grizzam)

    Got it, thanks for the reply Sasa! It would probably require some serious hacking to get the plugin to include that functionality. A feature request is probably the route.

    I use that plugin and it works great for one of my sites. But, you can just use the code straight from Pinterest to get pretty much the same result.

    Add this to which ever script calls your post, page, or whatever content type you want it to be displayed on:

    <!-- Please call pinit.js only once per page -->
    <script type="text/javascript" async  data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>

    That code was taken directly from Pinterest.

    You can also use conditional tags to filter it down to certain content types.

    Thread Starter grizzam

    (@grizzam)

    That works! I have this code:

    add_action( 'the_post', 'get_post_info' );
    
    	function get_post_info() {
    	    global $post;
    	    echo $post->ID;
    	    }

    It outputs this though: get_post_info(); 10

    The ID the the post I was on is 10, so it’s retrieving the variables I want. But it’s also outputting the function name. How do I get rid of that?

    Thread Starter grizzam

    (@grizzam)

    Hi dlngle,

    Thanks for the response. I added this inside a custom plugin:

    add_action( 'the_post', array( &$this, 'get_post_info') );
    
    	function get_post_info() {
    	    global $post;
    	    var_dump( $post );
    	    }

    But, I get this error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /Applications/XAMPP/xamppfiles/htdocs/wp-includes/plugin.php on line 507

    That code is literally all I have in the plugin. It gives that error when I go into any post. I literally just want to be able to pull data about the current post. Any ideas?

    Thread Starter grizzam

    (@grizzam)

    Note: if anyone is using this as a reference, disregard the first and second code examples (use the last one). I only included part of the wp_link_pages function (I cut it off after the array). Use the last one.

    Thread Starter grizzam

    (@grizzam)

    I just threw this together. It’s really hacky, but it works:

    add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
    
    function wp_link_pages_args_prevnext_add($args) {
        global $page, $numpages, $more, $pagenow;
    
        if (!$args['next_or_number'] == 'next_and_number')
            return $args; # exit early
    
        $args['next_or_number'] = 'number'; # keep numbering for the main part
        if (!$more)
        	return $args; # exit early
    
        if($page - 1) { # there is a previous page
            $args['before'] .= _wp_link_page($page - 1)
                . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>';
    		} else { # First page of pagination
    
    			$prev_url = get_permalink(get_adjacent_post(false, '', true));
    			$args['before'] = '<div class="page-links"><a href="'.$prev_url.'">Last</a>';		
    
    			}
    
        if ($page < $numpages) { # there is a next page
            $args['after'] = _wp_link_page($page + 1)
                . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
                . $args['after'];
    		} else { # Last page of pagination
    
    			$next_url = get_permalink(get_adjacent_post(false, '', false));
    			$args['after'] = '<a href="'.$next_url.'">Next</a>';
    
    			}
    
        return $args;
    }
    
    function wp_link_pages( $args = '' ) {
    	$defaults = (array(
        'before' => '<p>' . __('Pages:'),
        'after' => '</p>',
        'next_or_number' => 'next_and_number', # activate parameter overloading
        'nextpagelink' => __('Next'),
        'previouspagelink' => __('Last'),
        'pagelink' => '%',
        'echo' => 1 )
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    	$r = apply_filters( 'wp_link_pages_args', $r );
    	extract( $r, EXTR_SKIP );
    
    	global $page, $numpages, $multipage, $more;
    
    	$output = '';
    	if ( $multipage ) {
    		if ( 'number' == $next_or_number ) {
    			$output .= $before;
    			for ( $i = 1; $i <= $numpages; $i++ ) {
    				$link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after;
    				if ( $i != $page || ! $more && 1 == $page )
    					$link = _wp_link_page( $i ) . $link . '</a>';
    				$link = apply_filters( 'wp_link_pages_link', $link, $i );
    				$output .= $separator . $link;
    			}
    			$output .= $after;
    		} elseif ( $more ) {
    			$output .= $before;
    			$i = $page - 1;
    			if ( $i ) {
    				$link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>';
    				$link = apply_filters( 'wp_link_pages_link', $link, $i );
    				$output .= $separator . $link;
    			}
    			$i = $page + 1;
    			if ( $i <= $numpages ) {
    				$link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>';
    				$link = apply_filters( 'wp_link_pages_link', $link, $i );
    				$output .= $separator . $link;
    			}
    			$output .= $after;
    		}
    	}
    
    	$output = apply_filters( 'wp_link_pages', $output, $args );
    
    	if ( $echo )
    		echo $output;
    
    	return $output;
    }

    The only setbacks are these:

    If you’re on the first tab, the last button will bring you to the first tab of the previous article (not the last tab). I’m sure I can figure out a way to fix that, it might actually be better how it is. Everything else is functional.

    You can see it working HERE. The “Next” button brings you to the next article. Then the “Last” button on the next article brings you back to the first tab of the previous article (There’s only 2 articles at this point in time, so it’s not ideal for demonstration purposes).

    Thanks xavortm!

    Thread Starter grizzam

    (@grizzam)

    One more thing xavortm. Once you get to the last pagination tab, is there a way to show the “Next” button and have it go to the next post? Right now, it doesn’t show a “Next” button on the last tab, nor does it show a “Previous” button on the first. I want it to show those buttons because it would raise page views per visitor substantially.

    Here’s an example of the last tab.

    Thread Starter grizzam

    (@grizzam)

    Wow thanks man. I used the code from stack exchange and it worked perfectly. If anyone’s wondering, just overwrite the entire wp_link_pages function with this:

    add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
    
    function wp_link_pages_args_prevnext_add($args)
    {
        global $page, $numpages, $more, $pagenow;
    
        if (!$args['next_or_number'] == 'next_and_number')
            return $args; # exit early
    
        $args['next_or_number'] = 'number'; # keep numbering for the main part
        if (!$more)
            return $args; # exit early
    
        if($page-1) # there is a previous page
            $args['before'] .= _wp_link_page($page-1)
                . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . ''
            ;
    
        if ($page<$numpages) # there is a next page
            $args['after'] = _wp_link_page($page+1)
                . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . ''
                . $args['after']
            ;
    
        return $args;
    }
    
    function wp_link_pages( $args = '' ) {
    	$defaults = (array(
        'before' => '<p>' . __('Pages:'),
        'after' => '</p>',
        'next_or_number' => 'next_and_number', # activate parameter overloading
        'nextpagelink' => __('Next'),
        'previouspagelink' => __('Previous'),
        'pagelink' => '%',
        'echo' => 1 )
    );
    Thread Starter grizzam

    (@grizzam)

    Got it! Is there a way to have both “next” and “numbers?” I want it so the “Previous” and “Next” buttons appear to the left and right of all the numbers.

    I altered the code to this:

    function wp_link_pages( $args = '' ) {
    	$defaults = array(
    		'before'           => '<p>' . __( 'Pages:' ),
    		'after'            => '</p>',
    		'link_before'      => '',
    		'link_after'       => '',
    		'next_or_number'   => 'next',
    		'separator'        => ' ',
    		'nextpagelink'     => __( 'Next page' ),
    		'previouspagelink' => __( 'Previous page' ),
    		'pagelink'         => '%',
    		'echo'             => 1
    	);

    Like you said, it just shows the “Previous” and “Next.” How can it show both?

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