• Resolved berez

    (@berez)


    I made ??a separate page template (added sidebar), this page contains all the posts. Pagination works!
    But, if this page set as the home page, pagination is not working!
    Please help find solutions myself I can not …

    This my code

    <?php
    /*
    Template Name: Шаблон страницы с сайдбаром
    */
    
    ?>
    
     <?php get_header () ; ?>
    
     <div id="container" class="cf">
    <h1 class="cat-title"> <?php single_cat_title(); ?> </h1>
    <?php query_posts( array('showposts' => 0, 'paged' => get_query_var('paged') ) ); ?>
    	 <?php if (have_posts()) : while (have_posts()) : the_post();?>
    
     <div class="post post-left">
    
    <div class="post-image">
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
    </div>
    		   <h1 class="entry-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="К посту <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    
              		  <div class="entry-content">
              <?php the_content(); ?>
    
    		  <div class="entry-readmore"><a href="<?php the_permalink(); ?>" class="more-link">Читать полностью</a></div>
    		  </div>
           <div class="entry-meta">
    	<div class="meta-inner">
            <span class="date">
                <strong class="day"><?php the_time('d') ?></strong>
                <div class="holder">
                    <div class="month"><?php the_time('M') ?></div>
                    <div class="year"><?php the_time('Y') ?></div>
                </div>
            </span>
            <span class="author">
                <strong class="title">АВТОР</strong><br />
                <?php the_author_posts_link() ?>        </span>
            <span class="cat">
                <strong class="title">РУБРИКА</strong><br />
            <?php the_category(); ?>      </span>
            <span class="Tags">
                <strong class="title">МЕТКИ</strong><br />
               <?php the_tags(''); ?></span>
                        <span class="comments">
                    <strong class="title">КОММЕНТАРИИ</strong><br>
                    <?php comments_popup_link( 'Комментариев нет', '1 комментарий', '% штука', 'comments-link', 'Админ закрыл напрочь комментирование'); ?>         </span>
                </div>
    
    </div>
    </div>
    <?php get_sidebar('Sidebar'); ?>
    		 <?php endwhile; ?>
    
    		 <div class='pagination'>
    		 <?php my_pagination(); ?>
    		 </div>
    
             <?php endif; ?>
    <?php wp_reset_query(); ?>
    
    	 </div>
    	 <?php get_footer () ; ?>

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator bcworkz

    (@bcworkz)

    What’s not working? The number of posts per page or the pagination links? The pagination links seem to be handled by “my_pagination()”, what is the code used for that function? (please use pastebin.com for sizable code snippets and simply provide a link here. Directly embedding short snippets is fine though)

    Thread Starter berez

    (@berez)

    Links are working, the page moves to the next, but the posts on this page are the same. That is the page switch positions but displays the same as on the first page. If you do not set this page as your home page, then it works.

    This code of my pagination

    This code of my custom posts page

    Thank you very much if you could help me! A good site https://pastebin.com

    This is working page https://berezovsky.org.ua/myblog/%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD-%D1%81-%D1%81%D0%B0%D0%B9%D0%B4%D0%B1%D0%B0%D1%80%D0%BE%D0%BC/

    But if you put as the main page ….

    Moderator bcworkz

    (@bcworkz)

    Thank you for posting your code on pastebin. The syntax highlighting makes code much easier to read. Everything looks good, there is no problem with your code.

    I believe I understand the problem now. It may be a misunderstanding of the various settings on the Reading Settings Screen. Since your screen is probably not in English, it may help to refer to a English Language Screen Image, though you obviously speak English very well.

    From what you posted so far, I understand you selected “A static page” option under “Front page displays”. Under that you’ve selected a page which uses the template you’ve shared as “Front page”. And not as “Posts page”, is this correct?

    If correct, the behavior is by design. The Front page setting is for displaying a single static page. Apparently no matter what you try to do with pagination, it displays the same. This is news to me as well. For your situation, you should leave the Front page selection unselected and select your page with the Posts page selection. You will see this selection only lists pages to select, just like the front page select.

    If you read the description of each option below the image, this arrangement makes sense once you know the situation. But on first reading, it is easy to not understand it correctly.

    If I’ve not understood your situation correctly, my apologies. Please tell where I’m wrong and I’ll reconsider your problem. I hope things are more clear and your problem is solved. Cheers.

    Thread Starter berez

    (@berez)

    I selected a page which uses the template you’ve shared as “Front page”. And not as “Posts page”,this is correct ?? my Engish is poor… very thanks – Google Translator ??

    Look – Screenshot Custom page as Front Page. This is code Custom Page

    Look here how this working

    Moderator bcworkz

    (@bcworkz)

    my Engish is poor… very thanks – Google Translator ??

    Fooled me! ?? Usually Google translate syntax is very bad, but it does well from your language to English. It works well for conveying general ideas, but is terrible for specific instruction. But let us try anyway ??

    Change your settings to look like this screenshot. This should make your site work as you desire.

    Thread Starter berez

    (@berez)

    It does not work on the front page shows a standard template index.php

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    else { $paged = 1; }
    query_posts( array( 'paged' => $paged ) );

    ‘page’ works on static front page. That is the truth of this hack ??

    Thread Starter berez

    (@berez)

    ?? It works. But again, I have the page as the home page, and now even post does not show, shows normal page.php

    I have this code on static front page – it works.
    Try to add wp_reset_query(); exactly above this lines.

    Thread Starter berez

    (@berez)

    Nothing …

    Thread Starter berez

    (@berez)

    I was told that
    “Never use query_posts. Very likely that’s what breaks the pagination. Use WP_Query` instead.”

    But I did not get to do the loop and show article with this function

    Thread Starter berez

    (@berez)

    Show Posts from Current Page

    Display posts from current page:

    $query = new WP_Query( array( 'paged' => get_query_var( 'paged' ) ) );
    Display posts from the current page and set the ‘paged’ parameter to 1 when the query variable is not set (first page).

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );

    Pagination Note: Use get_query_var(‘page’); if you want your query to work in a Page template that you’ve set as your static front page. The query variable ‘page’ also holds the pagenumber for a single paginated Post or Page that includes the <!–nextpage–> Quicktag in the post content.

    Display posts from current page on a static front page:

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );

    And what can i use this samples with loop???

    Thread Starter berez

    (@berez)

    I did it! thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘pagination does not work with query_posts. Help!’ is closed to new replies.