• Resolved hoss9009

    (@hoss9009)


    K… here’s my CPT:

    register_post_type('web', array('label' => 'Websites','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => true,'rewrite' => array('slug' => 'portfolio/web', 'has_archive' => 'archive-web'),'query_var' => true,'menu_position' => 5,'supports' => array('title','thumbnail'),'labels' => array (
      'name' => 'Websites',
      'singular_name' => 'Website',
      'menu_name' => 'Websites',
      'add_new' => 'Add a Website',
      'add_new_item' => 'Add a New Website',
      'edit' => 'Edit',
      'edit_item' => 'Edit Website',
      'new_item' => 'New Website',
      'view' => 'View Website',
      'view_item' => 'View Website',
      'search_items' => 'Search Websites',
      'not_found' => 'No Websites Found',
      'not_found_in_trash' => 'No Websites Found in Trash',
      'parent' => 'Parent Website',
    ),) );

    Here’s my loop:

    <?php $loop = new WP_Query( array( 'post_type' => 'web', 'posts_per_page' => 1 ) ); ?>
    <?php if ( $loop->have_posts() ) : ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="portfolio-item">
        <div class="portfolio-thumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="Portfolio item: <?php the_title_attribute(); ?>"><?php the_post_thumbnail('portfolio-thumb'); ?></a></div>
        <h4 class="portfolio-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Portfolio item: <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    </div>
    <?php endwhile; ?>
    <?php wp_pagenavi( array( 'query' => $loop ) ); ?>
    <?php wp_reset_postdata(); // reset the query ?>
    <?php endif; ?>

    I am using archive-{posttype}.php and am not using page templates. I’m trying to go 100% 3.1.
    As you can see I want my CPT w/ the slug page/post-type and I don’t know if this is the problem, but I have killed the page for testing and I still can’t get pagination to work.

    Please help!?!

    Thanks

Viewing 15 replies - 1 through 15 (of 23 total)
  • Thread Starter hoss9009

    (@hoss9009)

    … and yes… I made sure I was saving permalinks. ??

    Moderator keesiemeijer

    (@keesiemeijer)

    see if this helps:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'web', 'posts_per_page' => 1, 'paged' => $paged ) ); ?>

    Thread Starter hoss9009

    (@hoss9009)

    I did this…

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'web', 'posts_per_page' => 1, 'paged' => $paged ) ); ?>
    
    <?php if ( $loop->have_posts() ) : ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="portfolio-item">
    
        <div class="portfolio-thumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="Portfolio item: <?php the_title_attribute(); ?>"><?php the_post_thumbnail('portfolio-thumb'); ?></a></div>
    
        <h4 class="portfolio-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Portfolio item: <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    
    </div>	
    
    <?php endwhile; ?>
    <?php wp_pagenavi( array( 'query' => $loop ) ); ?>
    
    <?php wp_reset_postdata(); // reset the query ?>
    
    <?php endif; ?>

    then saved permalinks…. no go.
    ??

    Moderator keesiemeijer

    (@keesiemeijer)

    try first to see if pagination is working with next_posts_link and previous posts link In stead of wp_pagenavi pagination.

    Thread Starter hoss9009

    (@hoss9009)

    Interesting… I put them right next to the wp_pagenavi(which is working – i think), and I get nothing. I even put a comma between the two… all I see is the comma.

    Moderator keesiemeijer

    (@keesiemeijer)

    from twentyten:

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

    try it with this.

    Thread Starter hoss9009

    (@hoss9009)

    still no go. ??

    Moderator keesiemeijer

    (@keesiemeijer)

    You don’t see any links? Did you put them in the right template file? do you have more than one cpt “web” Post published. is your template file archive-web.php? Do you only see cpt “web” Posts on this page?

    Thread Starter hoss9009

    (@hoss9009)

    Here’s the loop now….

    [Code moderated as per the Forum Rules. Please use the pastebin]

    here’s a link.

    Moderator keesiemeijer

    (@keesiemeijer)

    try registering this way: example

    Moderator keesiemeijer

    (@keesiemeijer)

    and put this in stead of the html <body> tag so we can see what template file is being used and more:
    <body <?php body_class($class); ?>>

    Thread Starter hoss9009

    (@hoss9009)

    Man oh man… you got it working!!!

    A few things…

    1. The slug is set to true, so “websites” is now a working url on my site along w/ the “portfolio/web”. The loop for register_post_type('web',$args); works on both pages. This is good to know, but leads me to #2 on my list.
    2. There is no “slug” (I know it’s a rewrite array) and I need it “portfolio/web”. I tried changing it and I get the 404 when the select the 2nd page.
    3. When I implemented the registration that you gave me, it only produces the wp_pagenavi on the 1st page. The twentyten nav and wp_pagenavi appear on the 2nd page. Odd.
    4. I did implement the body_class. Thank you for that.

    Link.

    Thoughts?

    Thank you so much for everything thus far.

    PS. Is it wishful thinking that the WP would understand “parent/child” permalinks for CPTs with the currect released build (3.1)?

    Thread Starter hoss9009

    (@hoss9009)

    Also, I notice that the single pages of the CPT is:
    https://www.capichedesignstudio.com/web/asfasf/

    If possible, I’m wanting it:
    https://www.capichedesignstudio.com/portfolio/web/asfasf/.

    Moderator keesiemeijer

    (@keesiemeijer)

    use this for the rewriting:

    'rewrite' => array('slug' => 'portfolio/web'),

    change this in your custom post archive template:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array( 'post_type' => 'web', 'posts_per_page' => 1, 'paged' => $paged ) ); ?>
    
    <?php if ( $loop->have_posts() ) : ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    into a normal loop:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    and put this in your theme’s functions.php:

    function my_custom_posts_per_page( &$q ) {
    	    if ( $q->is_archive ) // any archive
    	    if($q->query_vars['post_type'] == 'web'){  //custom post type "web" archive
            $q->set( 'posts_per_page', 1 );
    	    }
    	   	return $q;
    	}
    
    add_filter('parse_query', 'my_custom_posts_per_page');

    and re-save your permalink structure.

    your permalinks will be
    archive: https://www.capichedesignstudio.com/portfolio/web/
    single posts: https://www.capichedesignstudio.com/portfolio/web/asfasf/

    Thread Starter hoss9009

    (@hoss9009)

    You’re amazing.

    It works. 100%. Perfect.

    Can you explain the function? Please?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Another WP 3.1 CPT Archive Pagination Problem’ is closed to new replies.