Ako zabrániť duplicitnému zobrazeniu v magazínových témach pre WordPress

Fintou je ZAPAMäTAť SI pri prvom prechode ID článkov a pri ďalších tieto ID vylúčiť.

The problem. Due to the recent popularity of “magazine” themes, there’s a high demand from WordPress users who use more than one loop on their blog home page for a solution to avoiding duplicate posts on the second loop.

The solution. Here’s a simple solution to that problem, using the power of PHP arrays.

Code explanation. When the first loop is being executed, all IDs of posts contained within it are put into an array variable. When the second loop executes, we check that the current post ID hasn’t already been displayed in the first loop by referring to the array.

10 Killer WordPress Hacks | How-To | Smashing Magazine

Zdieľať?