I can't go to the second page even if I set the page Nation.

Asked 2 years ago, Updated 2 years ago, 373 views

I'm a beginner.I'm creating a homepage with WordPress.
Currently
Page Nation Settings on the Post Archive Page I'm going.
The first page appears when you press the button on another page.
If you know how to solve this problem, please.

I don't know PHP, so I would appreciate it if you could explain it in detail.

Below is the code.

PHP

<?php the_posts_pagination(
 
    array(  
        'mid_size' = > 2, // Number of page numbers to display on the left and right sides of the current page
        'prev_next' = > false, // True to display 'forward' or 'next' links
        'type' = > 'list', // Specify return value (plain/list)
        'prev_text' = > __('forward'), // Text in the 'forward' link
        'next_text' = > __('Next'), // Text in the 'Next' link
        'paged' = > get_query_var('paged') // I added this ★); 
    )
);?>

CSS

.pagination{
  display:flex;
}

h2.screen-reader-text{
  display: none;
}

ul.page-number {
  display:flex;

  li{
    width —3.75vw;
    height —3.75vw;
    border —1px solid#1b224c;
    text-align:center;
    line-height —3.90625vw;
    margin-right —1.484375vw;
    
  }
   li —last-child {
  margin-right:0vw;
}

  span.page-number.current{
    font-size —1.6 rem;
    text-decoration: none;
    font-weight:bold;
    color:#FFF;/* The text color of the current page */
    background: #1b224c; /* Current Page Background Color */ 
    padding —1.3vw 1.4vw 1.3vw 1.4vw;
  }

  li —nth-of-type(4){
    border: none;
  }
}

span.page-number.current{
  font-size —1.6 rem;
  text-decoration: none;
  color: #1b224c;
  font-weight:bold;
}

a.page-number {
  font-size —1.6 rem;
  text-decoration: none;
  color: #1b224c;
  font-weight:bold;
}
.pagination{
  display:flex;
  margin:0 auto;
  width:25.46875vw;
  padding-bottom —3.515625vw;
}

The code itself was in the net and added 'paged'=>get_query_var('paged')//★);
I picked this up from another site (it may heal if I put it in, but it doesn't heal)

Also, when you go to the second page, there is no parentheses for 4.
I would appreciate it if you could let me know what I should do.

I'm in a hurry, so I'm planning to ask questions on other sites.

Enter a description of the image here

Enter a description of the image here

php wordpress

2022-09-30 22:02

1 Answers

We decided to add a plug-in (WP-PageNavi) and start from scratch.

<div class="pagination">
    <div class="list-box">
        <ul>
        <?php
        $paged=(get_query_var('paged'))?get_query_var('paged'):1;
        $the_query=newWP_Query(array(
            'post_status' = > 'public',
            'post_type' = > 'post', // Page type (e.g., page, post, custom post type)
            'paged' = > $paged,
            'posts_per_page' = > 10, // Views
            'orderby' = > 'date',
            'order' = > 'DESC'
        ) );
        if($the_query->have_posts()):
            while($the_query->have_posts())—$the_query->the_post();
            ?>
                <?php//Show a list of blogs start?>
                <?php if(have_posts()):while(have_posts()):the_post();?>
                    <article class="blog-list__list-item">
                        <a href="<?php the_permalink();?>"class="blog-item">
                            <?php//Show eye catch start?>    
                            <div class="blog-item_thumbnail-second">
                                <?php if(has_post_thumbnail()):?>
                                <img class="blog-item_thumbnail-image-second" src="<?php the_post_thumbnail_url('large');?>">
                                <?php endif;?>
                            </div>
                            <?php//end?> to display eye catch
                            <div class="blog-item__content">
                                <?php//start to display title?>
                                <h3class="blog-item__title">?php the_title();?>/h3>
                                <?php//end?> to display the title
                                <?php//start to display excerpts?>
                                <h3class="blog-item__read"><?php the_excerpt();?>/h3>
                                <?php//end?> to display excerpts
                                <div class="blog-item__button">
                                    <span class="blog-item__button-more">Read Articles</span>
                                </div>
                            </div>
                        </a>
                    </article>
                    <?php break;?>
                    <?php endwhile;?>
                    <?php while(have_posts()):the_post();?>

                    <article class="blog-list__list-item">
                        <a href="<?php the_permalink();?>"class="blog-item">
                            <?php//Show eye catch start?>    
                            <div class="blog-item__thumbnail">
                                <?php if(has_post_thumbnail()):?>
                                <img class="blog-item_thumbnail-image" src="<?php the_post_thumbnail_url('large');?>">
                                <?php endif;?>
                            </div>
                            <?php//end?> to display eye catch
                            <div class="blog-item__content">
                                <?php//start to display title?>
                                <h3class="blog-item__title">?php the_title();?>/h3>
                                <?php//end?> to display the title
                                <?php//start to display excerpts?>
                                <h3class="blog-item__read"><?php the_excerpt();?>/h3>
                                <?php//end?> to display excerpts
                                <div class="blog-item__button">
                                    <span class="blog-item__button-more">Read Articles</span>
                                </div>
                            </div>
                        </a>
                    </article>
                    <?php endwhile;?>
<?php endif;?>

                <?php//View a list of blogs end?>
                <?php break;?>
            <?php
            endwhile;
        else:
            echo'<div><p> none.</p></div>';
        endif;
        ?>
        </ul>
    </div>

It's done now.
Re-use the code you picked up on a different net from the location,

<?php if(have_posts()):?>
<?php while(have_posts()):the_post();?>

<!--Layout of first post-->

<!--Show one and break through the loop-->
<?php break;?>
<?php endwhile;?>

<!--The loop should start with the second one-->
<?php while(have_posts()):the_post();?>

<!--Layout of second and subsequent posts-->

<?php endwhile;?>
<?php endif:?>

That's how it worked.

<?php break;?>

It is done by adding at the end to stop the loop.
Thank you all for your cooperation.


2022-09-30 22:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.