我想要获取每个类别中的最新帖子的id,并使用该id获取元信息和缩略图,并显示它旁边的相应类别。我只是不知道该怎么做。从类别档案中的类别的最新帖子获得id
我一直想这个代码,但它不是为我工作:
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) : ?>
<?php $randpost = get_posts(
array(
'numberposts' => 1,
'category' => array(get_query_var($category->id)),
));
$randpostid = ($randpost->ID);
?>
<?php echo '<h2 class="newsitem"><a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '>' . $category->name.'</a> </h2> '; ?>
<?php echo '<p>'. $category->count . ' nummer</p>'; ?>
<strong>Stad:</strong>
<?php $city = get_post_meta($randpostid, 'city', true); ?>
<?php echo $city ?>
<?php endforeach; ?>
我在做什么错?
解决了它,非常感谢!我一整天都在b my我的头。 –