WordPress.org

Ready to get started?Download WordPress

Forums

How To Add PageNavi to Twenty Eleven WordPress Theme ? (20 posts)

  1. Rohit Tripathi
    Member
    Posted 3 years ago #

    How to Add PageNavigation to WordPress Twenty Eleven Theme.

    I Have Installed the PageNavi Plugin. Now What to do ?

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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(); ?>

  3. frantsch
    Member
    Posted 3 years ago #

    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!

  4. Rohit Tripathi
    Member
    Posted 3 years ago #

    @alcymyth What ever u said Doesn't works.

    Please help us only if you have done it urself.

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.

  6. Rohit Tripathi
    Member
    Posted 3 years ago #

    Would you please Mind Giving step by Step Process ?

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.

  8. Rohit Tripathi
    Member
    Posted 3 years ago #

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

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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

  10. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    @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.

  11. OmcD
    Member
    Posted 3 years ago #

    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.

  12. Rohit Tripathi
    Member
    Posted 3 years ago #

    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.

  13. frantsch
    Member
    Posted 3 years ago #

    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...

  14. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

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

  15. frantsch
    Member
    Posted 3 years ago #

    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

  16. zeaks
    Member
    Posted 3 years ago #

    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

  17. zeaks
    Member
    Posted 3 years ago #

    Figured I'd add this. If you want it to show on category pages, you'll need to edit category.php and edit line 44 the same way index.php was edited in the above post.

  18. RobIrizarry
    Member
    Posted 3 years ago #

    @Zeaks - Thanks! Good stuff. You avoided the issue by simply calling a different function name.

    The alternative would be to override the existing function with your own. That way you don't need an index.php in your child theme just for this. This article does a good job of going over the steps - The Right Way to Override Theme Functions.

  19. RobIrizarry
    Member
    Posted 3 years ago #

    @rohitink - Good article (How To Add Wp-PageNavi To WordPress Twenty Eleven) if you're editing the parent theme and not creating a child theme. Otherwise, you need to Zeak's method or you need to override the original theme function as I mention above.

    One other thing - In your article, you state if you "wish to Stylize the Plugin you need to Edit Plugin Files". That's actually not the case. You can style them in style.css after disabling 'Use pagenavi-css.css' in the plugin's settings. Here's example CSS from one of my blogs where I do just this:

    .wp-pagenavi a, .wp-pagenavi a:link, .wp-pagenavi a:active{padding:2px 4px 2px 4px; font-size:12px; margin:2px; text-decoration:none; border:1px solid #666; color:#000; background-color:#fff}
    .wp-pagenavi a:hover{border:1px solid #A90000; font-size:12px; color:#000; background-color:#FFF7D3}
    .wp-pagenavi span.pages{padding:2px 4px 2px 4px; font-size:12px; margin:2px 2px 2px 2px; border:1px solid #CCC; color:#666; background-color:#FFF}
    .wp-pagenavi span.current{padding:2px 4px 2px 4px; font-size:12px; margin:2px; font-weight:bold; border:1px solid #A90000; color:#666; background-color:#FFF7D3}
    .wp-pagenavi span.extend{padding:2px 4px 2px 4px; font-size:12px; margin:2px; border:1px solid #FFF; color:#666; background-color:#FFF}
  20. zeaks
    Member
    Posted 3 years ago #

    @RobIrizarry I did try to do it that way first, it would be better, but I couldn't get it to work for me.

Topic Closed

This topic has been closed to new replies.

About this Topic