Why doesn't the pager appear in page--taxonomy.tpl.php? $query = db_select('node', 'n');
$query = $query-&gt;condition('n.type', 'article', '=')
  -&gt;fields('n', array('nid', 'title', 'uid'))
  -&gt;extend('PagerDefault') 
  -&gt;limit(1);

$result = $query-&gt;execute();
while ($record = $result-&gt;fetchObject()) {
  echo $record -&gt;title."&lt;br/&gt;";
}

echo theme('pager');


If I put the code in page--node--3.tpl.php  there is a pager under the title. When I put the same code in page--taxonomy.tpl.php the title is output, but there is no pager. Why?

If there is a term ID, the pager will disappear.

template.php

function mythemename_preprocess_page(&amp;$vars)  {
 if (isset($vars['node']-&gt;type)) {
$nodetype = $vars['node']-&gt;type;
$vars['theme_hook_suggestions'][] ='page__' . $nodetype;
}

}
I tried with the Bartik theme, and it works.



The steps I followed as the following ones:


I copied the page.tpl.php file the Bartik theme has in its templates directory in the page--taxonomy.tpl.php file
Right before &lt;?php print render($page['content']); ?&gt;, I copied the following code.

&lt;?php
  $query = db_select('node', 'n');
  $query = $query-&gt;condition('n.type', 'article', '=')
    -&gt;fields('n', array('nid', 'title', 'uid'))
    -&gt;extend('PagerDefault') 
    -&gt;limit(1);

  $result = $query-&gt;execute();
  foreach ($result as $node_obj) {
    echo $node_obj-&gt;title . "&lt;br/&gt;";
  }

  echo theme('pager');
?&gt;

I selected another theme instead of the Bartik theme, disabled the Bartik theme, and then selected the Bartik theme as default one. (This step is probably not necessary, but I did it to be sure Drupal would notice I added a new template file.)
I visited http://tero.local/dr72/taxonomy/term/2.


If it doesn't work for you, I suggest trying with another theme, possibly one that comes with Drupal, for example the Bartik theme. Be sure you are adding the template file to the theme Drupal is using. If the theme selected for the current user is another one, the template file is not being used, and that would explain why you are not getting any output.

This is what I suspect, as the code doesn't depend from arg(2). You just need to visit a page whose path starts with taxonomy, for example http://example.com/taxonomy/term/2, or http://example.com/taxonomy/term. (Replace example.com with the domain you should use for your site.)

Update

It works, but using the following code.

&lt;?php
  $query = db_select('node', 'n');
  $query = $query-&gt;condition('n.type', 'article', '=')
    -&gt;fields('n', array('nid', 'title', 'uid'))
    -&gt;extend('PagerDefault')
    -&gt;element(10) 
    -&gt;limit(1);

  $result = $query-&gt;execute();
  foreach ($result as $node_obj) {
    echo $node_obj-&gt;title . "&lt;br/&gt;";
  }

  echo theme('pager', array('element' =&gt; 10));
?&gt;


Apparently, there is a conflict between the pager added from Drupal, and the pager added from my code. This is the reason why such code should not be added to a template file. Rather than using this method, it is better to override the taxonomy term page with other methods, such as the Views module, or implementing hook_menu_alter() in a custom module.

Using the Bartik module this is the output I get:


When there aren't nodes using that taxonomy term


When there are nodes using that taxonomy term




Any different result could be caused from the code used for the specific theme used on the site. Understanding what exactly causes the different behavior seems a little outside the purpose of this site, as it is too localized to be helpful for future readers, considering that similar code should not written in a template file.