в моем шаблоне category.php Я хочу показывать последние записи только в том случае, если они имеют одну и ту же категорию, и когда я выполняю пользовательский запрос, отображаются все записи.Wordpress показать последние записи категории по пользовательскому запросу
Это мой код, как я могу исправить ошибку? Код:
<?php
/**
* The template for displaying all single posts.
*
* @package Mundo Geek
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main-single" class="site-main" role="main">
<div id="row">
<?php
$ultimas = new WP_Query();
$ultimas -> query('showposts=3');
while($ultimas -> have_posts()) : $ultimas ->the_post();
?>
<div class="category_page_last col-xs-12 col-sm-4">
<a href="<?php the_permalink(); ?>">
<div class="thumb">
<?php
if(has_post_thumbnail()){
//echo '<img src="'.$url.'"/>';x
$backgroundImageUrl = "('".wp_get_attachment_url(get_post_thumbnail_id($post->ID))."')";
echo '<div class="category_page_img-background" style="background-image: url'.$backgroundImageUrl.'"></div>';}
else{
$default_thumb = "('".get_bloginfo('stylesheet_directory')."/images/default-thumbnail.jpg')";
echo '<div class="category_page_img-background" style="background-image: url'.$default_thumb.'"></div>';
}
?>
<div class="encimaimagen"></div>
</div>
<div class="meta"><h1><?php the_title(); ?></h1></div>
</a>
</div>
<?php endwhile; ?>
</div>
<div class="row">
<div class="col-sm-8">
<section id="category_page">
<?php
$ultimas = new WP_Query();
$ultimas -> query('showposts=40');
while($ultimas -> have_posts()) : $ultimas ->the_post();
?>
<article class="col-xs-12 archivo row">
<a href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a>
<div class="hidden-xs col-sm-4 col-md-3"><?php the_post_thumbnail('thumbnail'); ?></div>
<div class="col-sm-8 col-md-9"><?php the_excerpt(); wp_reset_postdata();?></div>
</article>
<?php endwhile; ?>
</section>
</div>
<div class="col-sm-4 hidden-xs"><?php get_sidebar(); ?></div>
<div class="index_archivo col-xs-12">
<a href="<?php $url = home_url($path = 'index.php/archivo', $scheme = relative); echo $url;?>">
<h2>Ver todas las entradas</h2>
</a>
</div>
</div>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
Спасибо, ребята!
Вы можете получить недавний пост с этой функцией - https: // Codex. wordpress.org/Function_Reference/wp_get_recent_posts – SevStryker