How to implement pager in custom page template? 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-&gt;entityCondition('entity_type', 'node');
$query-&gt;propertyCondition("type","news");
$query-&gt;fieldCondition("field_news_typ","value","Topnews","=");
$query-&gt;propertyOrderBy("created","DESC");
$query-&gt;range(0,1);
$result = $query-&gt;execute();


Then I output the topnews with its special HTML and use this code to get all other news:

$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'node');
$query-&gt;propertyCondition("type","news");
$query-&gt;propertyOrderBy("created","DESC");
$result = $query-&gt;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 -&gt;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.
This can and should almost certainly be done entirely with the Views module (which is/will be in Drupal 8 core!). The filtering of your content by type and the value of the "top news" field can all be done with Views, along with the ajax pager. You can then use the Views attachment display type to attach those news items which do not have the "top news" box checked. You may also want to look into the Nodequeue module for ordering content in more ambiguous ways than just the most recent or whatnot, but you can also use Drupal's "sticky" setting on nodes that you want to keep at the top of the list and highlight, format them differently, etc. Views also allows you to rewrite the output of every item in the results in the UI or using tpl files. Views, my friend. Views.