Answer the question
In order to leave comments, you need to log in
How to display posts on the page according to a certain "algorithm"?
Guys, help me make the output of the posts in this way:
First, the posts for the last week are displayed, then for the last month, and after the list of months of the year
Maybe something like that, and I'll try to do the
rest myself
<?php get_header(); ?>
<?php
// get options
$pinthis_infinite_scroll = get_option('pbpanel_infinite_scroll');
$pinthis_columns_num = get_option('pbpanel_columns_num');
?>
<div class="line-block">
<div class="RocketBot"></div>
<div id="down"></div>
</div>
<section id="content">
<div class="container <?php echo $pinthis_columns_num; ?>">
<?php if (is_category()) { ?>
<div class="category-title">
<div class="container">
<h3 class="title-3"><?php single_cat_title(); ?></h3>
<?php if (category_description()) { ?><div class="description"><?php echo category_description(); ?></div><?php } ?>
</div>
</div>
<?php } ?>
<?php if ( have_posts() ) { ?>
<div class="boxcontainer">
<?php while ( have_posts() ) { the_post(); ?>
<?php get_template_part('pinbox', get_post_format()); ?>
<?php } ?>
</div>
<?php
ob_start();
posts_nav_link(' ', __('Previous Page', 'pinthis'), __('Next Page', 'pinthis'));
$pinthis_posts_nav_link = ob_get_clean();
?>
<?php if(strlen($pinthis_posts_nav_link) > 0) { ?>
<div class="container">
<div class="posts-navigation clearfix <?php if ($pinthis_infinite_scroll == 1) { ?>hide<?php } ?>"><?php echo $pinthis_posts_nav_link; ?></div>
</div>
<?php } ?>
<?php } else { ?>
<div class="notification-body">
<p class="notification tcenter"><?php echo __('No posts found.', 'pinthis'); ?></p>
</div>
<?php } ?>
</div>
</section>
<?php get_footer(); ?>
А это подгрузка постов при бесконечном скролле
/*====================================*\
SET POST PER PAGE
\*====================================*/
function pinthis_posts_per_page($query) {
$user_posts_per_page = get_option('posts_per_page');
if ($user_posts_per_page < 10) {
update_option('posts_per_page', 10);
}
}
add_action('pre_get_posts', 'pinthis_posts_per_page');
/*====================================*\
Answer the question
In order to leave comments, you need to log in
This is how we display the posts for the last week:
<?php
// WP_Query arguments
$last_month_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
// Using the date_query to filter posts from last week
'date_query' => array(
array(
'after' => '1 week ago'
)
)
);
// The Query
$last_month_posts = new WP_Query( $last_month_args );
// The Loop
if ( $last_month_posts->have_posts() ) {
while ( $last_month_posts->have_posts() ) {
$last_month_posts->the_post();
// контент поста
the_title();
the_post_thumbnail();
}
} else {
// Если постов нет
}
// Restore original Post Data
wp_reset_postdata();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question