in my theme I need a custom front page which displays a filtered set of news and paginated. The news are nodes with content type=news, and every one has a field "is topnews", so that only the freshest topnews is displayed at the top and all other news are displayed (with another layout) below the topnews.
So I created a page--node--9.tpl.php (which corresponds to the "empty" frontpage I created in the drupal backend), and used this code to get the topnews:
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition("type","news");
$query->fieldCondition("field_news_typ","value","Topnews","=");
$query->propertyOrderBy("created","DESC");
$query->range(0,1);
$result = $query->execute();
Then I output the topnews with its special HTML and use this code to get all other news:
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition("type","news");
$query->propertyOrderBy("created","DESC");
$result = $query->execute();
In the iterator loop I check the node-id against the topnews-node-id and output regular HTML for the news if they don't match. Now I want to add a pager to the mess so I can paginate the "normal news", but adding a ->pager(3)
to the second query before the execute()
call does not work and a var_dump(theme("pager"))
returns NULL
.
So there are two questions:
a) how do I make a pager (bonus points: the end result should be an AJAX pager which loads the HTML for ordinary news!) and
b) how do I move all that logic out of the .tpl.php and instead follow the "proper" drupal way? I imagine that having the "ordinary" and "topnews" HTML in separate .tpl.php files would be helpful in implementing said AJAX paging.