作为您已经拥有的内容的简单扩展,无需太多修改,请考虑将您的视频数组制作为多维数组,并使用一个键指示它应该保持在一起。keeptogether => TRUE
在对它们进行分页时,如果您在页面列表的末尾遇到一个,而不是中断,继续循环输出直到到达下一个keeptogether => FALSE
。(我还将建立将keeptogether
键省略为FALSE
值的能力)。
$videolist = array(
array("title" => "example1", "keeptogether" => FALSE),
array("title" => "example2", "keeptogether" => FALSE),
array("title" => "example3", "keeptogether" => TRUE),
array("title" => "example4", "keeptogether" => TRUE),
array("title" => "example5" "keeptogether" => FALSE)
);
如果您需要它在 a 出现在页面末尾时更优雅地工作keeptogether => TRUE
,并且它应该在继续之前中断到下一页(因此当前页面不会变得太长),请考虑一个简单的算法,例如:
# Pseudocode:
# Encountering a keeptogether == TRUE when 2 from the end of a normal page length:
if current_page_counter < (num_per_page - 2) and keeptogether == TRUE
break_to_next_page
else
loop_until keeptogether == FALSE