Last active
July 14, 2022 20:17
-
-
Save frontend-coder/abf15ed7adfa11707e8126c1f63d46f2 to your computer and use it in GitHub Desktop.
37. Як вивести пости за допомогою WP_Query #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function domain_paginate($query) { | |
$big = 999999999; | |
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_paged, | |
)); | |
} | |
<?php domain_paginate($cars1); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'car', | |
'posts_per_page' => -1, | |
) | |
$cars = new WP_Query($args); | |
?> | |
<?php if( $cars->have_posts() ) : while( $cars->have_posts() ) : $cars->the_post(); ?> | |
<?php get_template_part('part/content', 'cars'); ?> | |
<?php endwhile; else: ?> | |
<?php get_template_part('part/content', 'none'); ?> | |
<?php endif; wp_reset_postdata(); ?> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args1 = array( | |
'post_type' => 'post', | |
'posts_per_page' => 5, | |
'order' => 'ASC', | |
'orderby' => 'date', | |
) | |
$cars1 = new WP_Query($args1); | |
?> | |
<?php if( $cars1->have_posts() ) : while( $cars1->have_posts() ) : $cars1->the_post(); ?> | |
<?php get_template_part('part/content', 'cars'); ?> | |
<?php endwhile; else: ?> | |
<?php get_template_part('part/content', 'none'); ?> | |
<?php endif; wp_reset_postdata(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$args1 = array( | |
'post_type' => 'post', | |
'posts_per_page' => 5, | |
'paged' => $paged, | |
'order' => 'ASC', | |
'orderby' => 'date', | |
) | |
$cars1 = new WP_Query($args1); | |
?> | |
<?php if( $cars1->have_posts() ) : while( $cars1->have_posts() ) : $cars1->the_post(); ?> | |
<?php get_template_part('part/content', 'cars'); ?> | |
<?php endwhile; ?> | |
<div class="pagination"> | |
<?php | |
$big = 999999999; | |
echo paginate_links( array( | |
'base' => str_replace($big, '%#%', esc_url( get_pagenum_link( $big ))), | |
'format' => '?paged=%#%', | |
// archive - paged static pages - page | |
'current' => max(1, get_query_var('paged')), | |
'total' => $cars1->max_num_paged, | |
)); ?> | |
</div> | |
<?php | |
else: ?> | |
<?php get_template_part('part/content', 'none'); ?> | |
<?php endif; wp_reset_postdata(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment