Hi. I need help with some code

The website have 470 topics, but loads only 10 from the first page. when i click 2,3 etc it also loads topic from the first. Here is the code

<?php
/* Template Name: News */
get_header();
?>

<div class="pozadina-about-us-vlez">
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1 class="largeFont">
                <div class="grid__item color-11">
                <?php if (ICL_LANGUAGE_CODE == "mk"){?>
                <a class="link link--yaku" href="#">
                    <span class="wow fadeIn" data-wow-delay="2.2s">н</span><span class="wow fadeIn" data-wow-delay="2.3s">о</span><span class="wow fadeIn" data-wow-delay="2.4s">в</span><span class="wow fadeIn" data-wow-delay="2.5s">о</span><span class="wow fadeIn" data-wow-delay="2.6s">с</span><span class="wow fadeIn" data-wow-delay="2.7s">т</span><span class="wow fadeIn" data-wow-delay="2.8s">и</span>                           
                </a>
                <?php } else if (ICL_LANGUAGE_CODE == "en"){ ?>
                <a class="link link--yaku" href="#">
                    <span class="wow fadeIn" data-wow-delay="2.2s">N</span><span class="wow fadeIn" data-wow-delay="2.3s">e</span><span class="wow fadeIn" data-wow-delay="2.4s">w</span><span class="wow fadeIn" data-wow-delay="2.5s">s</span>                            
                </a>
                <?php } ?>
            </div>
            </h1>
            <h1 class="smallFont">
                <?php
                if (ICL_LANGUAGE_CODE == "mk")
                    echo '<p class="wow fadeIn" data-wow-delay="2.0s">Новости</p>';
                if (ICL_LANGUAGE_CODE == "en")
                    echo '<p class="wow fadeIn" data-wow-delay="2.0s">News</p>';
                ?>
            </h1>
        </div>
    </div>
</div>

<div class="container news-sidebar wow fadeInLeftBig" data-wow-delay="2.9s">
    <div class="row">
    

        <?php
        $paged = (get_query_var('page')) ? get_query_var('page') : 1;
        $args = array(
          'post_type' => 'news',
          'post_status' => 'publish',
          'posts_per_page' => 10,
          'paged'    => $paged
        );
        $query = new WP_Query( $args );
        $i = 0;
        if ( $query->have_posts() ) {
          while ( $query->have_posts() ) {
            $query->the_post();
            $news_id = get_the_ID();
            $featured_image_id = get_post_thumbnail_id($news_id);
            $featured_image = wp_get_attachment_image_src($featured_image_id, 'large');
            $image_url = $featured_image[0];
            $content = get_post_meta( $news_id, 'short_description', true );
            if ($i == 0) {
        ?>
        <div class="col-md-9 wow fadeInUpBig" data-wow-delay="3.2s">
        <?php } else { ?>
        <div class="col-md-9 wow fadeInUpBig" data-wow-delay="0.3s">
        <?php } ?>
            <div class="row">
                <div class="col-md-6">
                    <a href="<?php the_permalink(); ?>">
                        <img src="<?php echo $image_url; ?>" alt="" class="img-responsive">
                    </a>
                </div>
                <div class="col-md-6">
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                </div>
                <div class="col-md-6">
                    <h4><i class="fa fa-calendar" aria-hidden="true" style="margin-right: 10px;"></i><?php echo get_post_time('d.m.Y'); ?></h4>
                    <h4><i class="fa fa-clock-o" aria-hidden="true"></i><?php echo get_post_time('H:i'); ?></h4>
                    <!-- <h4>20:00</h4> -->
                </div>
                <div class="col-md-6">
                    <?php echo $content; ?>
                    <a href="<?php the_permalink(); ?>" class="btn btn-news btn-sm"><?php _e( "Повеќе", "ohleto" ); ?></a>
                </div>
            </div>
        </div>
        <?php $i++; }
        } ?>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col-md-12">
        <?php if ($query->max_num_pages > 1) { ?>
        <div class="pager" style="text-align: center;">
        <?php //previous_posts_link('Newer Posts'); echo paginate_links(); 
            $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' => $query->max_num_pages ,
                'prev_text' => __('«'),
                'next_text' => __('»')
            ) ); 
        ?>
        </div>
        <?php } ?>
<!-- <nav aria-label="Page navigation" id="div1">
  <ul class="pager">
    <li>
      <a href="#" aria-label="Previous">
        <span aria-hidden="true">«</span>
      </a>
    </li>
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
    <li>
      <a href="#" aria-label="Next">
        <span aria-hidden="true">»</span>
      </a>
    </li>
  </ul>
</nav> -->
        </div>
        </div>
    </div>
</div>
</div>

<?php
get_footer();
?>

Well, this really should be in the WordPress area not general help, but, does not matter…
You are sending data to a WP function somewhere else in your code named paginate_links. To debug this issue, you must look at that function and trace what is being sent to it. If the data sent to it, meaning the array of data, is correct, then the problem is in that function. If the data sent to it is incorrect, then it is in the code you posted.
Also, you use another function named get_query_var and send $paged to it. You might be sending the incorrect value to it. Since the “current” page stays at one, my guess is that the get_query_var(‘page’) part of the array is not calculating the value correctly and therefore sends “1” as the ‘current’ page.
Perhaps you should show us the get_query_var() function? Hard to follow your code without more info.

1 Like

That’s the whole code in php ErnieAlex

No, it can not be. You have dozens of function calls to routines. All of them are on your site in the WordPress folders somewhere. If this is a “canned” website, it will have documentation of each of these functions and you need to learn them all. If you wrote this WordPress code yourself, where are all the functions calls located? You did not show them. Some of these are:

get_header();
get_query_var();
new WP_Query();
get_post_meta();
etc…

These must be somewhere in your site. My guess is that you need to look at the page that loads all of this page and in there would be INCLUDE’s that add in other files. In them, you will find the items I mentioned before. And, look at the pagination sections I mentioned.

Does this make sense to you?

1 Like

[quote=“ErnieAlex, post:2, topic:33608”]
get_query_var(‘page’)
[/quote]`

<>

<?php /* Template Name: News */ get_header(); ?>

<?php if (ICL_LANGUAGE_CODE == "mk"){?> новости <?php } else if (ICL_LANGUAGE_CODE == "en"){ ?> News <?php } ?>

<?php if (ICL_LANGUAGE_CODE == "mk") echo '

Новости

'; if (ICL_LANGUAGE_CODE == "en") echo '

News

'; ?>
    <?php
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $args = array(
      'post_type' => 'news',
      'post_status' => 'publish',
      'posts_per_page' => 10,
      'paged'    => $paged
    );
    $query = new WP_Query( $args );
    $i = 0;
    if ( $query->have_posts() ) {
      while ( $query->have_posts() ) {
        $query->the_post();
        $news_id = get_the_ID();
        $featured_image_id = get_post_thumbnail_id($news_id);
        $featured_image = wp_get_attachment_image_src($featured_image_id, 'large');
        $image_url = $featured_image[0];
        $content = get_post_meta( $news_id, 'short_description', true );
        if ($i == 0) {
    ?>
    <div class="col-md-9 wow fadeInUpBig" data-wow-delay="3.2s">
    <?php } else { ?>
    <div class="col-md-9 wow fadeInUpBig" data-wow-delay="0.3s">
    <?php } ?>
        <div class="row">
            <div class="col-md-6">
                <a href="<?php the_permalink(); ?>">
                    <img src="<?php echo $image_url; ?>" alt="" class="img-responsive">
                </a>
            </div>
            <div class="col-md-6">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            </div>
            <div class="col-md-6">
                <h4><i class="fa fa-calendar" aria-hidden="true" style="margin-right: 10px;"></i><?php echo get_post_time('d.m.Y'); ?></h4>
                <h4><i class="fa fa-clock-o" aria-hidden="true"></i><?php echo get_post_time('H:i'); ?></h4>
                <!-- <h4>20:00</h4> -->
            </div>
            <div class="col-md-6">
                <?php echo $content; ?>
                <a href="<?php the_permalink(); ?>" class="btn btn-news btn-sm"><?php _e( "Повеќе", "ohleto" ); ?></a>
            </div>
        </div>
    </div>
    <?php $i++; }
    } ?>
</div>
<?php if ($query->max_num_pages > 1) { ?>
<?php //previous_posts_link('Newer Posts'); echo paginate_links(); $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' => $query->max_num_pages , 'prev_text' => __('«'), 'next_text' => __('»') ) ); ?>
<?php } ?>
<?php get_footer(); ?>

<>

This is the whole code from wordpress

Well, not really sure how to help you, but, this line calls a function called get_query_var and I would guess it is the current page number. If it does not return a page number, it assign’s it to page # 1.
Therefore, in the section that displays the page numbers for the pagination section

This appears to use a variable “paged” which is either the current page or 1 depending on the results form the previous code I noted. And, it is used inside the paginate_links() function. You need to locate that function and see what it does. My guess is that it is not creating your links correctly in that function. I do not see that function anywhere in the code you posted.

1 Like

I dont know what to do… Thanks a lot ErnieAlex for your time and help. I hope i’ll get it done somehow.

Frustrated? I understand. Altering WordPress systems can be annoying! So many pages behind the scenes for different areas. But, pagination is usually easy to sort out.

One thing you can try is to go to the live page and VIEW-SOURCE of the page. Then, look down to where the pagination links are posted and see what data is in them. If you do not know this, you can look at all the HTML and CSS code on any page in the world by just RIGHT-CLICK on it and select VIEW-SOURCE or VIEW-PAGE-SOURCE depending on the browser you are in. This will show you the code. It will NOT show you the PHP code, but, it will let you see what the PHP code is placing into the links for the pagination. Hope that helps.

The other way would be to hire someone to look at it, or to give your login info to someone here so they can see all your pages and sort it out for you. If you do that, please do not post that info live here. Post it to them in a PRIVATE message so the world does not get your login info.

Good luck!

1 Like

Tnx ErnieAlex, i’ll try.

Sry, can you send me private message for communication? I cant find how…

Sponsor our Newsletter | Privacy Policy | Terms of Service