WordPress.org

Ready to get started?Download WordPress

Forums

Advanced pages of category not found... (40 posts)

  1. dotsanddashes
    Member
    Posted 1 year ago #

    Hi there,

    So basically I've got a minor issue I'm struggling to get to the bottom of, and was hoping some kind soul out there somewhere or other may be able to help..!

    I'm having an issue with the archived pages of the 'Live' category on my site, Dots & Dashes. All is functioning fine and dandy, 'til I hit page 21 of the archives, at which point I'm getting a 'Page Not Found' error...

    Any ideas, anyone..?

    Thanks!
    Josh.

  2. tomontoast
    Member
    Posted 1 year ago #

    Is http://dotsanddashes.co.uk/live/joie-et-jouissance-camille-barbican-centre/ the oldest post in the live section?

    This is probably caused by an error in the theme and the way it displays only 4 posts per page.

  3. dotsanddashes
    Member
    Posted 1 year ago #

    It's not, no... It's odd, as whenever a new post in said category is added it just shunts the last one off into nowhere..! So when another now goes up, that Camille piece will no longer show in the section...

  4. tomontoast
    Member
    Posted 1 year ago #

    You will need to look in your theme. Its a custom theme so I can't work out whats going on. Did you create it yourself?

  5. dotsanddashes
    Member
    Posted 1 year ago #

    ah OK... Thanks anyway – I'll look into it... I had help on it, as I'm still no whiz when it comes to WordPress..!

  6. tomontoast
    Member
    Posted 1 year ago #

    Work out what theme php file your /links/ archive is using and post the loop of that file here and I'll try to debug.

  7. dotsanddashes
    Member
    Posted 1 year ago #

    OK so I think this is what you're after, though lemme know if not..?

  8. tomontoast
    Member
    Posted 1 year ago #

    No its not this. Its probably archive.php or category.php you are looking for see http://codex.wordpress.org/Template_Hierarchy

  9. dotsanddashes
    Member
    Posted 1 year ago #

    Ah OK – so could it be this one instead..?

    <?php
    /**
     * The template for displaying Live Category Archive pages.
     *
     *
     * @package DotsAndDashes
     *
     */
    
    get_header(); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    				<h1 class="page-title">Live</h1>
    				<?php
    					$category_description = category_description();
    					if ( ! empty( $category_description ) )
    						echo '<div class="archive-meta">' . $category_description . '</div>';
    
    				?>
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    
    <?php query_posts(array ( 'cat' => '5', 'posts_per_page' => 4,  'paged' => $paged)); ?>
    <?php if ( ! have_posts() ) : ?>
    	<div id="post-0" class="post error404 not-found">
    		<h1 class="entry-title"><?php _e( 'Not Found', 'dotsanddashes' ); ?></h1>
    		<div class="entry-content">
    			<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'dotsanddashes' ); ?></p>
    			<?php get_search_form(); ?>
    		</div><!-- .entry-content -->
    	</div><!-- #post-0 -->
    <?php endif; ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    		<div id="post-<?php the_ID(); ?>" <?php post_class(array('live-item')); ?>>
    			<div class="thumb-wrapper">
    				<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo( 'template_url' ); ?>/thumb.php?src=<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID));  ?>&h=300&w=715" alt="<?php echo the_title(); ?>"/></a>
    			<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'dotsanddashes' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php  echo get_post_meta($post->ID, 'Artist', true); ?><br><?php  echo get_post_meta($post->ID, 'Venue', true); ?></a></h2>
    			</div>
    		</div><!-- #post-## -->
    
    <?php endwhile; // End the loop. Whew. ?>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if (  $wp_query->max_num_pages > 1 ) : ?>
    				<div id="nav-below" class="navigation">
    					<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav"></span> <span class="pagi-bracket">[</span>Older<span class="pagi-bracket">]</span>', 'dotsanddashes' ) ); ?></div>
    					<div class="nav-next"><?php previous_posts_link( __( '<span class="pagi-bracket">[</span>Newer<span class="pagi-bracket">]</span> <span class="meta-nav"></span>', 'dotsanddashes' ) ); ?></div>
    				</div><!-- #nav-below -->
    <?php endif; ?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  10. tomontoast
    Member
    Posted 1 year ago #

    The custom loop you are using causes pagination to break.
    Try adding the following to your themes functions.php

    function custom_posts_per_page( $query ) {
        if ( is_category( 5 ) ) {
            // Display 4 posts if the category is 5
            $query->set( 'posts_per_page', 4 );
            return;
        }
    }
    add_action( 'pre_get_posts', 'custom_posts_per_page', 1 );

    then remove the following from the file you just posted.
    <?php query_posts(array ( 'cat' => '5', 'posts_per_page' => 4, 'paged' => $paged)); ?>

  11. dotsanddashes
    Member
    Posted 1 year ago #

    and can I add that new piece of coding anywhere in the functions.php file..?

  12. tomontoast
    Member
    Posted 1 year ago #

    You certainly can, well obviously not in the middle of another function!

  13. dotsanddashes
    Member
    Posted 1 year ago #

    So at the bottom I've got this:

    * Is SubPage?
    *
    * Checks if the current page is a sub-page and returns true or false.
    *
    * @param  $page mixed optional ( post_name or ID ) to check against.
    * @return boolean
    */
    function mv_is_subpage( $page = null )
    {
        global $post;
        // is this even a page?
        if ( ! is_page() )
            return false;
        // does it have a parent?
        if ( ! isset( $post->post_parent ) OR $post->post_parent <= 0 )
            return false;
        // is there something to check against?
        if ( ! isset( $page ) ) {
            // yup this is a sub-page
            return true;
        } else {
            // if $page is an integer then its a simple check
            if ( is_int( $page ) ) {
                // check
                if ( $post->post_parent == $page )
                    return true;
            } else if ( is_string( $page ) ) {
                // get ancestors
                $parent = get_ancestors( $post->ID, 'page' );
                // does it have ancestors?
                if ( empty( $parent ) )
                    return false;
                // get the first ancestor
                $parent = get_post( $parent[0] );
                // compare the post_name
                if ( $parent->post_name == $page )
                    return true;
            }
            return false;
        }
    }
    
    ?>

    Could I just alter that to read:

    * Is SubPage?
    *
    * Checks if the current page is a sub-page and returns true or false.
    *
    * @param  $page mixed optional ( post_name or ID ) to check against.
    * @return boolean
    */
    function mv_is_subpage( $page = null )
    {
        global $post;
        // is this even a page?
        if ( ! is_page() )
            return false;
        // does it have a parent?
        if ( ! isset( $post->post_parent ) OR $post->post_parent <= 0 )
            return false;
        // is there something to check against?
        if ( ! isset( $page ) ) {
            // yup this is a sub-page
            return true;
        } else {
            // if $page is an integer then its a simple check
            if ( is_int( $page ) ) {
                // check
                if ( $post->post_parent == $page )
                    return true;
            } else if ( is_string( $page ) ) {
                // get ancestors
                $parent = get_ancestors( $post->ID, 'page' );
                // does it have ancestors?
                if ( empty( $parent ) )
                    return false;
                // get the first ancestor
                $parent = get_post( $parent[0] );
                // compare the post_name
                if ( $parent->post_name == $page )
                    return true;
            }
            return false;
        }
    }
    
    function custom_posts_per_page( $query ) {
        if ( is_category( 5 ) ) {
            // Display 4 posts if the category is 5
            $query->set( 'posts_per_page', 4 );
            return;
        }
    }
    add_action( 'pre_get_posts', 'custom_posts_per_page', 1 );
    
    ?>
  14. tomontoast
    Member
    Posted 1 year ago #

    Yes thats great

  15. dotsanddashes
    Member
    Posted 1 year ago #

    ah amazing – thank you ever so much!

  16. tomontoast
    Member
    Posted 1 year ago #

    You have the same problem on other pages when you click on older on http://dotsanddashes.co.uk/features/page/7/

    To fix this you need to add more categories to the function
    if ( is_category( 5 ) or is_category( 6 ) ) {
    I have assumed that category is 6 (it might not be)

  17. dotsanddashes
    Member
    Posted 1 year ago #

    ah you're right... so before I only had an issue with this particular category, though it now seems to have affected the Blog, Reviews, and the Features... So what do I need to do exactly now..?

  18. tomontoast
    Member
    Posted 1 year ago #

    No I checked before that it affected all categories! You just need to find out the ids of those categories and update the is_category if statement to include those categories.

  19. dotsanddashes
    Member
    Posted 1 year ago #

    Ah OK – my bad! But it's not the exact same coding that needs to go in for each category, is it..?

  20. tomontoast
    Member
    Posted 1 year ago #

    Sorry I don't understand your question. You just need to extend the if statement to include all categories.

  21. dotsanddashes
    Member
    Posted 1 year ago #

    so to do that, I just separate the numbers with commas, right..?

    The issue is then that certain categories need to show more posts than others...

    So the Reviews need to be on six and not four; the Blog on seven; the Live/ Features on four... I tried to alter the Features bit (id 110) but it's either stuck on the same broken page (page 8) or it's showing ten features at a time..?

  22. tomontoast
    Member
    Posted 1 year ago #

    Use something like

    function custom_posts_per_page( $query ) {
        if ( is_category( 5 ) or is_category( 110 ) ) {
            // Display 4 posts if the category is live or features
            $query->set( 'posts_per_page', 4 );
            return;
        }
        if ( is_category( 7 ) ) {
            // Display 7 posts if the category is blog
            $query->set( 'posts_per_page', 7 );
            return;
        }
        if ( is_category( 8 ) ) {
            // Display 6 posts if the category is reviews
            $query->set( 'posts_per_page', 6 );
            return;
        }
    }
  23. dotsanddashes
    Member
    Posted 1 year ago #

    I'm getting an error on (I think it was) line 406 if I put that piece of code in, at which point the site breaks down...

    So were I to put that function in, what would I then need to do to the individual category php files..?

  24. tomontoast
    Member
    Posted 1 year ago #

    Oh dear I can't see any errors, what is the exact error and file and line number?

    You don't actually have to do anything to the individual category php files but it is best to remove the custom query
    <?php query_posts(array ( 'cat' => '5', 'posts_per_page' => 4, 'paged' => $paged)); ?>

  25. dotsanddashes
    Member
    Posted 1 year ago #

    that was my fault – didn't put the code in as it should've been and just as the raw, unformatted text...

    So I've inserted that new function though it's all the same as it was before – breaking off at the exact same pages..?

    Should it all snap back to how it should be if I remove those custom queries now..?

  26. dotsanddashes
    Member
    Posted 1 year ago #

    oh wait – I'm now getting ten features per page, too..?

  27. tomontoast
    Member
    Posted 1 year ago #

    Are you sure you set the right category ids?

  28. dotsanddashes
    Member
    Posted 1 year ago #

    Erm I had another look into the category ids, and came out with the following:

    function custom_posts_per_page( $query ) {
        if ( is_category( 5 ) or is_category( 110 ) ) {
            // Display 4 posts if the category is live or features
            $query->set( 'posts_per_page', 4 );
            return;
        }
        if ( is_category( 115, 1 ) ) {
            // Display 7 posts if the category is blog
            $query->set( 'posts_per_page', 7 );
            return;
        }
        if ( is_category( 111 ) ) {
            // Display 6 posts if the category is reviews
            $query->set( 'posts_per_page', 6 );
            return;
        }
    }

    The one thing I was wondering – where each tag says 'if the category is ...' should I try inserting the id as opposed to the name of the category..?

  29. dotsanddashes
    Member
    Posted 1 year ago #

    the blog has both 115 and 1, which is a little confusing..!

  30. tomontoast
    Member
    Posted 1 year ago #

    Where I have written

    if the category is
    is just a comment so you can follow what is going on.

    Havve you remembered the line
    add_action( 'pre_get_posts', 'custom_posts_per_page', 1 );

    Is this working now?

Topic Closed

This topic has been closed to new replies.

About this Topic