• Resolved VanDamage

    (@ralfjuh)


    Hi,

    I’ve been trying to get pagination to work in my custom theme, but can’t seem to figure it out. I searched forums and basically tried everything that fixes it for other people but still no succes for me. I mean it shows and all, but all the pages show the same content

    Here’s my template code:

    <?php
    /* Template Name: Portfolio */
    
    get_header(); 
    
    query_posts('post_type=portfolio&posts_per_page=9');
    
    ?>
    
    <div id="portfolio" class="group"> 
    
    <h1><?php the_title(); ?></h1>
    
    <div class="group">
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <?php
            $title= str_ireplace('"', '', trim(get_the_title()));
            $desc= str_ireplace('"', '', trim(get_the_content()));
        ?>   
    
        <div class="item">
                    <div class="img"><?php the_post_thumbnail(); ?></div>
                    <p><strong><?=$title?></strong> <?php print get_the_excerpt(); ?><br><?php $site= get_post_custom_values('projLink'); if($site[0] != ""){ ?><a href="<?=$site[0]?>" target="_blank">(Visit website)</a><?php }else{ ?>No website<?php } ?></p>
        </div>
    
    <?php endwhile; ?>
    
    <nav class="pagination">
    <?php pagination_bar(); ?>
    </nav>
     <?php else : ?>
    <!-- No posts found -->
    <?php endif; ?>
    </div>
    
    </div>
    
    <?php get_footer(); ?>

    This is in my functions.php:

    function pagination_bar() {
        global $wp_query;
    
        $total_pages = $wp_query->max_num_pages;
    
        if ($total_pages > 1){
            $current_page = max(1, get_query_var('paged'));
    
            echo paginate_links(array(
                'base' => get_pagenum_link(1) . '%_%',
                'format' => '/page/%#%',
                'current' => $current_page,
                'total' => $total_pages,
            ));
        }
    }

    Also I’m trying to show the portfolio items randomly.. No succes either 🙁

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter VanDamage

    (@ralfjuh)

    Hi,

    Before I tried WordPress default function I already tried PageNavi.
    It does the same thing, it shows, just like it does now, only with some styling (PageNavi’s default style). When I click the pagination (doesn’t matter which page) it always shows the same content.

    Now I also searched this through on Google. Guess it has something to do with query_posts() but I can’t figure out what it is.

    I used the link below to add it to my theme.
    http://www.elegantthemes.com/blog/tips-tricks/how-to-add-pagination-to-wordpress

    Thread Starter VanDamage

    (@ralfjuh)

    Can someone help me with this?
    Would be awesome 😉

    Thread Starter VanDamage

    (@ralfjuh)

    Fixed it by using this:

    global $wp_query;
    query_posts( array('post_type' => array( 'portfolio' ),'showposts' => 9, 'paged'=>$paged )

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination shows same content / randomize portfolio view’ is closed to new replies.