0

I've inserted posts in my homepage with pagination using php. My problem is when I click page 2 or other pages the content of homepage is always there but the posts are good they are changing. I would make the other pages only having post not on what is in homepage content. Can anyone help me? What logic should I do?

<?php

global $post;

$args = array(
    'paged' => get_query_var('paged'),
    'post_type'=> 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6, // this will retrive all the post that is published
);
$result = new WP_Query( $args );
if($result->have_posts()){
    while($result->have_posts()){
        $result->the_post();
        $count = get_post_meta( get_the_ID(), 'post_views_count', true );
        $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
    ?>
        <div class="post-content <?php the_ID();?>">
            <?php if(!empty($post_thumbnail_id)) {
                $img_ar =  wp_get_attachment_image_src( $post_thumbnail_id, 'medium' );
                ?>
                <img src="<?php echo $img_ar[0];?>">
            <?php
            }?>
            <h2 class="title"><?php the_title() ?></h2>
            <p class="author">By <?php the_author();?></p>
            <p class="date"> <?php the_date()?> </p>
            <p class="views"> <?php echo gapp_get_post_pageviews(); ?> Views </p>
            <p> <?php the_excerpt();?> </p> 
        </div>
        
    <?php   
        }
     
        $big = 999999999;
        $total_pages = $result->max_num_pages;
        if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'mid_size' => 5,
            'end_size' => 2,
            'prev_next' => true,
            'prev_text'    => __('PREV'),
            'next_text'    => __('NEXT'),
        ));
    }       
        wp_reset_postdata();
}   
?>      

 
  • Do you want hide the content of home page for other pages when you click on pagination button? – Hossein Shourabi Jul 13 '22 at 00:42
  • Kind of, I want to display only posts for other links except page 1 because page 1 is my homepage. Like when I click page 2 the link will hompage.com/page/2 yet it display only posts. then when I click button 1 it will display homepage. Once again my homepage have a posts below the content. – Gerald Yvan Cabarrubias Jul 13 '22 at 00:53

0 Answers0