我想要獲取每個類別中的最新帖子的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我的頭。 –