0
我試圖把2個單獨的飼料拉到我的WordPress主頁(最近的投資組合工作&最近的博客文章)。我希望兩套都坐在同一個UL內。我已經設法吸引投資組合飼料,但我在博客飼料方面遇到了麻煩。PHP - 結合最近的帖子與最近的工作
<ul>
<?php
$args = array('post_type' => 'work', 'posts_per_page' => 4);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >';
echo '<div class="recent-thumb">'; the_post_thumbnail(); echo '</div>';
echo '<div class="recent-title"><span>'; the_title(); echo '</span></div>';
echo '</a></li>';
endwhile;
?>
<?php
$args = array('post_type' => 'post', 'posts_per_page'=> 4);
$the_query = new WP_Query($args);
while ($the_query -> have_posts()) : $the_query -> the_post();
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >';
echo '<div class="home-blog-category">'; user_the_categories(); echo '</div>';
echo '<div class="home-blog-title">'; the_title(); echo '</div>';
echo '<div class="home-blog-excerpt">'; echo excerpt(27); echo '</div>';
echo '<span class="home-blog-plus"><span class="home-blog-plus-wrap"><span class="horizontal"></span><span class="vertical"></span></span></span>';
echo '</a></li>';
endwhile;
?>
</ul>
任何人都可以幫助獲取張貼飼料拉?我相信這不是最有效的方法,所以如果任何人有更好的方法來組合這兩個,那也將不勝感激!我對PHP的知識非常有限:)
乾杯!
好吧,但我的'後'陣列不工作,你知道爲什麼嗎? – Baz
在新的WP_Query($ args)之前使用** wp_reset_query()**; https://codex.wordpress.org/Function_Reference/wp_reset_query –