WordPress.org

Ready to get started?Download WordPress

Forums

Static start page template, wp_query, pagination (7 posts)

  1. CaptainCrunch
    Member
    Posted 1 year ago #

    Hey guys

    I'm pretty stuck. I'm working on a wordpress site, that uses a static start page template. I use wp-query to display excerpts from two categories on this page. It all works fine, however I somehow don't manage to add pagination. Right now, it displays all excerpts (or the number i'd like it to display). What I'd like to be able to do, is the start page to show a certain number of excerpts and the remaining ones on additional pages. I'm still pretty new to WP, and I've also tried several suggestions mentioned here in the forum, however, even if I get pagination to show up, all additional pages show the same excerpts…

    Here's the code as of now:

    <?php
    $my_query = new WP_Query('cat=1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20&showposts=15');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    if (in_category('Blog'))
    {
    ?>
    <div class="hentry_start">
    <p class="hentry_date_start"><?php the_time('d. F Y'); ?></p>
    <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/navigation/excerpt-line.gif" height="1" width="285" />
    <div class="excerpt_headline">
    <a <?php post_class(); ?> href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </div>
    <div class="excerpt_subline">
     								<?php if (function_exists('the_subheading')) { the_subheading('<p>', '</p>'); } ?>
    </div>
    <?php the_post_thumbnail(); ?>
    <?php the_content(); ?>
    </div>
    <?php
    }
    elseif (in_category('Publication'))
    {
    ?>
    <div class="hentry_start">
    <p class="hentry_date_start"><?php the_time('d. F Y'); ?></p>
    <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/navigation/excerpt-line.gif" height="1" width="285" />
    <div class="excerpt_headline">
    <a <?php post_class(); ?> href="<?php the_field('download'); ?>"><?php the_title(); ?></a>
    </div>
    <div class="excerpt_subline">
     								<p><?php the_field('titel'); ?> | <?php the_field('stars'); ?> | <?php the_field('coauthor'); ?></p>
    </div>
    <?php the_post_thumbnail(); ?>
    <p><?php echo custom_field_excerpt(); ?></p>
    <a class="btn_download_publicationen" href="<?php the_field('download'); ?>"></a>
    </div>
    <?php
    }
    ?>
    <?php endwhile; ?>
    
    <?php
    if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);
    ?>
    <?php endwhile; endif; ?>

    Any help is appreciated :-)

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    is this a static front page?

    Why not use (for example) "cat=1,2" or the "category__in" parameter for the two categories?
    http://codex.wordpress.org/Function_Reference/WP_Query#Category_Parameters

  3. CaptainCrunch
    Member
    Posted 1 year ago #

    Hey there,

    sorry for my late reply, I had quite a busy week... :-) Yes it's a static page. I'm using Thematic as underlying structure. Well, if I'd use your approach, would that solve my problem. As I see it — and correct me if I'm wrong — your link helps me to sort and display teasers of certain categories… The categories I'd like to display on this page all show up correctly. I'd just like to be able to limit those article-excerpts/teasers to... say... 10 per page and would then like WP to show a link to the remaining pages with teasers — all split up to 10 each page…

    Thanks so much…

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this:

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; }
    $my_query = new WP_Query('cat=1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20&posts_per_page=15&paged='.$paged);
  5. CaptainCrunch
    Member
    Posted 1 year ago #

    mmmh... So I put this in the very top spot of my code and overwrite the old $my_query? Can I then move on and add pagination somewhere else on the page?

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    Add one of these pagination functions after the first <?php endwhile; ?> (end of the loop).
    http://codex.wordpress.org/Pagination#Function_Reference

  7. CaptainCrunch
    Member
    Posted 1 year ago #

    hey keesiemeijer,

    alright, pagination shows up and works, thanks so much for your help :-)

    I used this: http://codex.wordpress.org/Function_Reference/paginate_links

    It displays all the pages in numbers and links them accordingly. That's all fine and it does work correctly. However, I wonder how to get the 'Previous' 'Next' links to work? -- Those won't get listed…

    Here's my code

    <?php
    global $my_query;
    
    $big = 999999999;
    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'total' => $my_query->max_num_pages,
    'prev_next' => $my_query->True,
    'prev_text' => __('&laquo; Previous'),
    'next_text' => __('Next &raquo;')
    ) ) ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.