<?php
$posts = get_posts( array(
'numberposts' => 6,
'order' => 'ASC',
'post_type' => 'post-want',
) );
foreach( $posts as $post ){
setup_postdata($post);
?>
<a class="projects__item projects__item--mini" href="<?php the_permalink(); ?>">
<picture class="projects__item-image">
<?php the_post_thumbnail('post-project'); ?>
</picture>
<div class="projects__item-info">
<h5 class="projects__item-title"><?php the_title(); ?></h5>
<div class="projects__item-text">
<?php the_excerpt() ?>
</div>
</div>
</a>
<?php
}
wp_reset_postdata();
?>
<?php get_header('want') ?>
<main class="page-want__main">
<div class="container page-want__container">
<div class="projects">
<div class="projects__search">
<div class="projects__form">
<form class="form form-search" action="/" method="GET">
<label class="form__label form-search__label">
Поиск
<input type="search" class="form__input form-search__input" name="search" placeholder="Я ищу...">
<span class="form__filter form-search__filter">
<span class="form-search__filter-button">фильтр</span>
</span>
</label>
</form>
</div>
<a class="button projects__button" href="<?php echo home_url(); ?>/add-project">Добавить свой проект</a>
</div>
<div class="projects__items">
<div class="projects__items-list">
<?php
$posts = get_posts( array(
'numberposts' => 6,
'order' => 'ASC',
'post_type' => 'post-want',
) );
foreach( $posts as $post ){
setup_postdata($post);
?>
<a class="projects__item projects__item--mini" href="<?php the_permalink(); ?>">
<picture class="projects__item-image">
<?php the_post_thumbnail('post-project'); ?>
</picture>
<div class="projects__item-info">
<h5 class="projects__item-title"><?php the_title(); ?></h5>
<div class="projects__item-text">
<?php the_excerpt() ?>
</div>
</div>
</a>
<?php
}
wp_reset_postdata();
?>
</div>
</div>
<?php the_post_pagination();
</div>
</div>
</main>
<?php get_footer('want'); ?>
get_posts
не работает, нужно менять на WP_Query, я нашел тут сей код: <?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'custom_post_type_name',
'posts_per_page' => 10,
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
//CPT. content
endwhile;
?>
<nav class="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );
?>
</nav>
<?php wp_reset_postdata(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 6,
'order' => 'ASC',
'post_type' => 'my_type_post',
'paged' => $paged
);
$loop = new WP_Query( $args );
?>
<?php
if( $loop->have_posts() ) {
while( $loop->have_posts() ){
$loop->the_post();
?>
<h3><?php the_title(); ?></h3>
// My HTML
<?php
}
wp_reset_postdata();
}
?>
// И в нужно контейнере - месте размещаем nav.
<code lang="php">
<nav class="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );
?>
</nav>
</code>