WordPress.org

Support

Support » Themes and Templates » How To Add PageNavi to Twenty Eleven WordPress Theme ?

How To Add PageNavi to Twenty Eleven WordPress Theme ?

Viewing 15 replies - 1 through 15 (of 19 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    look into functions.php of twenty eleven; find:

    function twentyeleven_content_nav( $nav_id ) {

    after that line, possibly replace:

    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>

    with (if you referring to the ‘wp-pagenavi’ plugin):
    <?php wp_pagenavi(); ?>

    When I do so adding functions.php to my twenty eleven child theme and replacing the respective section as described above, I obtain the error below:

    Fatal error: Cannot redeclare twentyeleven_excerpt_length() (previously declared in /var/www/vhosts/[blogname]/httpdocs/wordpress/wp-content/themes/twentyeleven_child/functions.php:318) in /var/www/vhosts/[blogname]/httpdocs/wordpress/wp-content/themes/twentyeleven/functions.php on line 320

    Any ideas?

    Thanks!

    @alcymyth What ever u said Doesn’t works.

    Please help us only if you have done it urself.

    You can’t just add the functions.php from twentyeleven to a child theme. It doesn’t work that way, and doing that is what caused your error.

    Would you please Mind Giving step by Step Process ?

    function twentyeleven_content_nav( $nav_id ) {
    	global $wp_query;
    
    	if ( $wp_query->max_num_pages > 1 ) : ?>
    		<nav id="<?php echo $nav_id; ?>">
    			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    			<?php wp_pagenavi(); ?>
                      </nav><!-- #nav-above -->
    	<?php endif;
    }

    Drop this into the functions.php of your child theme. I’m not 100% on this, I don’t have pagenavi installed, nor do I care to install it for testing.

    Remember, you can’t just copy twentyeleven’s functions.php over

    If you do not yet have one in your child theme, make a blank functions.php, and put the above code in it don’t forget the first line must be

    <?php

    Sometimes functions can just be overridded from a child theme. Sometimes actions need to be removed, etc.

    Do U Want me to Simple Add it at the Bottom or edit or replace something ?

    I don’t know what your child theme has in it already….

    If you have a functions.php, just add that block of code to it

    If not, make one and add that code with an opening php tag.

    Just don’t copy twentyelevens over and try to use it

    I believe that just putting that into a child theme’s functions.php will overwrite the function from the parent, but I’m not 100%

    It’s a technique I used a lot on a twentyten child theme

    Chip Bennett

    @chipbennett

    Theme Review Admin

    @alcymyth What ever u said Doesn’t works.

    Please help us only if you have done it urself.

    Note that Alcymyth said, “…after that line, possibly replace….”

    Code examples generally should not be expected to be copy-and-paste. You need to have some understanding of what code does, and how to apply it to your unique circumstances.

    Would you please Mind Giving step by Step Process ?

    That’s not always – and in fact, most often, not – possible.

    For specific help with the WP PageNavi Plugin, you should probably be posting your support request on the forum specific to that Plugin, which you can find here, rather than in the Themes and Templates general forum.

    Change the functions.php (line 427 to 436) to:

    function twentyeleven_content_nav( $nav_id ) {
    global $wp_query;

    if ( $wp_query->max_num_pages > 1 ) : ?>
    <nav id=”<?php echo $nav_id; ?>”>
    <h3 class=”assistive-text”><?php _e( ‘Post navigation’, ‘twentyeleven’ ); ?></h3>
    <?php wp_pagenavi(); ?>
    </nav><!– #nav-above –>
    <?php endif;
    }

    Plugin works now.

    Okay Problem Solved. Thanks. I Created a Details Instructions For Others Who are Seeking Help:

    How To Add Wp-PageNavi To WordPress Twenty Eleven

    Thanks Again.

    I do not agree on the “problem solved”!

    I copied the functions.php to my child theme directory and replace the
    specific section by the code as described above by OmcD, however I still obtain the Fatal Error message, whatever page of my blog I try to access!

    It does not seem to having anything to do with the entered code. Already at the moment when I copy the functions.php to the child theme dir, everything crashes. Once I delete it again there, everything works fine…

    Chip Bennett

    @chipbennett

    Theme Review Admin

    @frantsch: you should start a new thread. Your problem is different from the Original Poster’s issue.

    To all who are interested, there is a specific thread on the problems with the functions.php and child themes, however no solution in sight there so far:
    wordpress.org/support/topic/child-theme-functionsphp-breaks-admin

    Just tried to add this to a child theme and got it working.
    First create a functions.php for your child theme and add

    // Show Wp-PageNavi when it's active
    function twentyeleven_child_content_nav( $nav_id ) {
    	global $wp_query;
    	if ( $wp_query->max_num_pages > 1 ) : ?>
    	   <?php /* add wp-pagenavi support for posts */ ?>
    		<?php if(function_exists('wp_pagenavi') ) : ?>
    			<?php wp_pagenavi(); ?>
    			<br />
    				<?php else: ?>
    		<nav id="<?php echo $nav_id; ?>">
    			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
    		</nav><!-- #nav-above -->
    	<?php endif; ?>
    	<?php endif;
    }

    Next copy index.php to your child theme folder and change line 31 to
    <?php twentyeleven_child_content_nav( 'nav-below' ); ?>

    If wp-pagenavi is installed it will show it, if it isn’t, it’ll show the default next/previous

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘How To Add PageNavi to Twenty Eleven WordPress Theme ?’ is closed to new replies.