Grouped by Category

Simply displaying a list of categories may not attract readers to go further clicking the links. To give equal exposure to older, noteworthy Posts in other categories, especially when there is sparse posting in that category, another view of Posts is needed.

Grouping by category lays out Posts of same category under one heading, the category name.

 

The code above shows Loops as many as five. Each Loop is responsible for processing a set of Posts of a different category (Fig. 1); each set of Posts is first retrieved by get_posts() .

Categories list

Fig. 1

Line 5 fetches the first set of Posts. It passes to get_posts() the category of 2–the category id of Modern Science–and numberposts of 3. The variable $posts, then, contains at most 3 latest Posts of category Modern Science.

Line 11-15 loops thru the previously set variable $posts (Line 5) and output the desired corresponding Post data on line 13.

The rest of the code is simply the repeat of the first Posts retrieval and Loop (line 5-19) with different categories.

The last Loop (line 69-83), however, is treated slightly differently. Instead of displaying the link to the Post, which all previous Loops do, the last Loop displays the content of the Post (line 77). The last Loop process the category Inline Function which acts as regular news updates, whereas Posts of other categories are to be published sparingly.