• I have this code for my page template.

    This is what i have right now: https://www.ohright.com/emoticons/

    How do I change it so that it can display all my post images at 20 images per-page and with a pagination below? Please help. This is driving me crazy. Thank you so much!!!!

    <?php
    /*
    Template Name: emoticons-page
    */
    get_header(); ?>
    
    <div id="content">
    <div id="main">
    	<?php query_posts('cat=44'.get_the_title().'&post_status=publish,future');?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    	<p><?php the_content(); ?>
    	<?php endwhile; else: endif; ?>
    </div>
    </div>
    
    <?php get_footer(); ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    See:
    https://codex.www.ads-software.com/Pagination
    Try it with this:

    <?php
    /*
    Template Name: emoticons-page
    */
    get_header(); ?>
    
    <div id="content">
    <div id="main">
    
    <?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    $args = array(
    	'posts_per_page' => 20,
    	'posts_status' => array( 'publish', 'future' ),
    	'paged' => $paged,
    	'cat' => 44,
    );
    // the query
    $the_query = new WP_Query( $args );
    ?>
    	<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    	<p><?php the_content(); ?>
    
    	<?php endwhile; ?>
    
    <?php
    next_posts_link( 'Older Entries', $the_query->max_num_pages );
    previous_posts_link( 'Newer Entries' );
    ?>
    
    	<?php else: endif; ?>
    </div>
    </div>
    
    <?php get_footer(); ?>

    https://codex.www.ads-software.com/Function_Reference/next_posts_link
    https://codex.www.ads-software.com/Function_Reference/previous_posts_link

    https://codex.www.ads-software.com/Function_Reference/WP_Query

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.

    Thread Starter goloops

    (@goloops)

    Wow!!! Thank you so much keesiemeijer!!!! I almost cried when I see the result! You are my savior!!

    Just one more request, is there anyway that I can change the pagination to something like, ( ? Prev 1 … 3 4 5 6 7 … 9 Next ? )

    or make use of this plugin: https://www.ads-software.com/plugins/wp-pagenavi/screenshots/

    I read this link: https://codex.www.ads-software.com/Function_Reference/paginate_links and I tried to replace this

    <?php
    next_posts_link( 'Older Entries', $the_query->max_num_pages );
    previous_posts_link( 'Newer Entries' );
    ?>

    with this

    <?php
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    ?>

    But it doesn’t seem to work…:(

    Moderator keesiemeijer

    (@keesiemeijer)

    Change this:

    'total' => $wp_query->max_num_pages

    to this:

    'total' => $the_query->max_num_pages

    https://codex.www.ads-software.com/Function_Reference/paginate_links#Example_With_a_Custom_Query

    For wp-pagenavi you have to use this:

    <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>

    https://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html

    Thread Starter goloops

    (@goloops)

    keesiemeijer, you should look at my face, tears all over now!!!!!

    YOU MAKE MY DAY!!!! Have a great weekend ahead!!!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad you’ve got it resolved ??

    Thread Starter goloops

    (@goloops)

    Hi keesiemeijer, sorry to disturb you again, do you have any idea what code to change in order to make this code to display the first image of the posts in that categroy on a page?

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    $args = array(
    	'posts_per_page' => 10,
    	'posts_status' => array( 'publish', 'future' ),
    	'paged' => $paged,
    	'cat' => 44,
    );
    // the query
    $the_query = new WP_Query( $args );
    ?>
    
    	<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    	<div class=" display-posts-listing .listing-item">
    	<?php the_content(); ?>
        </div>
    
    	<?php endwhile; ?>
    
    <?php
        wp_pagenavi( array( 'query' => $the_query ) );
    ?>
    	<?php else: endif; ?>

    I found this link :https://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it
    but have no idea how to integrate in in this code above.
    Thank you so much for your help again!!!!

    Moderator keesiemeijer

    (@keesiemeijer)

    Paste the code from the link in your theme’s functions.php file and change this:

    <div class=" display-posts-listing .listing-item">
    <?php the_content(); ?>
    </div>

    to this:

    <div class=" display-posts-listing .listing-item">
    <?php echo catch_that_image() ?>
    <?php the_content(); ?>
    </div>

    Thread Starter goloops

    (@goloops)

    WOW! it works great!! is there a way to defining the resolution of the images displayed? Thanks again keesiemeijer for your quick response!!!

    Do I put something inside the () in this line
    <?php echo catch_that_image() ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display Post image on Custom Page Template with Pagination’ is closed to new replies.