我發現va_get_dashboard_favorites功能的其他地方看起來是一樣的。最簡單的方法是限制va_get_dashboard_favorites()WP_Query。例如
方法1
此代碼是在可溼性粉劑內容/主題/有利-新/發現包括/ dashboard.php順便說:
function va_get_dashboard_favorites($user_id, $self = false) {
$favorites = new WP_Query(array(
'connected_type' => 'va_favorites',
'connected_items' => $user_id,
'nopaging' => true,
'posts_per_page' => 3, // limiting posts to 3
));
return $favorites;
}
然後添加一個視圖 - 所有鏈接,只需將它添加到iunder while循環中即可。例如
<?php
$favorites = va_get_dashboard_favorites($dashboard_user->ID, (bool) $is_own_dashboard);
if ($favorites->post_count > 0) {
while ($favorites->have_posts()) : $favorites->the_post();
$post_status = $is_own_dashboard ? 'post-status' : '';
?>
<article id="post-<?php the_ID(); ?>" <?php post_class($post_status); ?>>
<?php get_template_part('content-listing', get_post_status()); ?>
</article>
<?php
endwhile;
?>
<br /><a href="#yourview-all-link-here">View all</a>
<?php
} else {
?>
方法2(已更新爲每個操作的更新)
按OP的評論,更新的代碼只顯示3個鏈接
<?php
$favorites = va_get_dashboard_favorites($dashboard_user->ID, (bool) $is_own_dashboard);
$counter = 0;
$max = 3;
if ($favorites->post_count > 0) {
while ($favorites->have_posts() and ($counter < $max)) : $favorites->the_post();
$post_status = $is_own_dashboard ? 'post-status' : '';
?>
<article id="post-<?php the_ID(); ?>" <?php post_class($post_status); ?>>
<?php get_template_part('content-listing', get_post_status()); ?>
</article>
<?php
$counter++;
endwhile;
?>
<br /><a href="#yourview-all-link-here">View all</a>
<?php
} else {
?>
我改變了代碼升技。我不想限制帖子的數量,但只是顯示的鏈接數量 – user2798091
OP更新了代碼,檢查方法#2。 – Braunson
謝謝..但你提供的代碼限制了帖子,而不是用'