• malyo

    (@malyo)


    Witam,

    Mam taki oto problem. Chciałbym na stronie głównej wyświetlać posty typu custom a także paginować je także na głównej stronie. Przy obecnym kodzie kliknięcie „starsze posty” w paginacji powoduje przeniesienie na podstronę /page/2 wraz z 404 errorem. Oto mój kod pętli:

    <?php
    global $wp_query;
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $args = array('post_type' => 'video_news', 'posts_per_page' => 5, 'paged' => $paged);
    $wp_query = new WP_Query($args); ?>
    <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
        <h2><?php the_title(); ?></h2>
    <?php endwhile; ?>
    <div class="pagination">
        <?php previous_posts_link( 'Newer posts &raquo;' ); ?>
        <?php next_posts_link('Older &raquo;') ?>
    </div>
    <?php wp_reset_postdata(); ?>
    <?php else:  ?>
        <p><?php _e( 'No results' ); ?></p>
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    Nie mam kompletnie punktu zaczepienia, aby rozwiązać ten problem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Paweł Knapek

    (@adpawl)

    A jak wygląda deklaracja owego CPT? Wrzuć jego kod.

    Twórca wątku malyo

    (@malyo)

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    	register_post_type( 'video_news',
    		array(
    			'labels' => array(
    				'name' => __( 'Videos' ),
    				'singular_name' => __( 'Video' )
    			),
    			'public' => true,
    			'taxonomies' => array('category'),
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'videos'),
    			'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
    		)
    	);
    }
    Moderator Paweł Knapek

    (@adpawl)

    No tak, przeczytałem trochę na skróty.

    Zobacz sobie >> http://wp.tutsplus.com/tutorials/custom-post-type-pagination-chaining-method/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Temat ‘Paginacja custom post type nad stronie głównej’ jest zamknięty na nowe odpowiedzi.