WordPress.org

Support

Support » How-To and Troubleshooting » Advanced pages of category not found…

Advanced pages of category not found…

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

Viewing 15 replies - 1 through 15 (of 39 total)
  • 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.

    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…

    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?

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

    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.

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

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

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

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

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

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

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

    Yes thats great

    ah amazing – thank you ever so much!

    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)

Viewing 15 replies - 1 through 15 (of 39 total)
  • The topic ‘Advanced pages of category not found…’ is closed to new replies.
Skip to toolbar