title: Simple pagination for foreach loop
body: <p>I need a pagination for the output that is generated by a WordPress plugin. The plugin retrieves all products of a certain productgroup from the datebase. The basic code is:</p>
  
  <pre><code>&lt;?php 
      foreach ((array)$this-&gt;view['data']['produkte'] as $p) 
      { ?&gt;
      ...some html code here
      } 
  ?&gt;
  </code></pre>
  
  <p>where <code>$p</code> is an multi-dimensional array that contains the data for the single product.
  I'd like to limit the output to, say, 10 products and create a simple pagination for that. The plugin is quite complex and uses nested templates, therefore a custom query is probably not an option in this case.</p>
  
  <p>Would be great if somebody could point me in the right direction. Thank you!</p>
  
  <p>Here's the final code. Thank you very much for your valuable help!!</p>
  
  <pre><code>&lt;?php
  $nb_elem_per_page = 3;      
  $page = isset($_GET['seite'])?intval($_GET['seite']-1):0;
  $data = (array)$this-&gt;view['data']['produkte'];
  $number_of_pages = intval(count($data)/$nb_elem_per_page)+2;
  $page_no = $_REQUEST['seite'];
  foreach (array_slice($data, $page*$nb_elem_per_page, $nb_elem_per_page) as $p) 
    { ?&gt; some HTML here... &lt;?php } ?&gt;
  &lt;?php if (count($data) &gt; $nb_elem_per_page) { ?&gt;       
  &lt;ul id='paginator'&gt;
    &lt;?php
    for($i=1;$i&lt;$number_of_pages;$i++){
    if ($i == $page_no) {?&gt;
      &lt;li&gt;&lt;?php echo $i ?&gt;&lt;/li&gt;
      &lt;?php }
      else { ?&gt;
      &lt;li&gt;&lt;a href="&lt;?php echo get_permalink(); ?&gt;?show=&lt;?php echo $_REQUEST['show']; ?&gt;&amp;seite=&lt;?=$i?&gt;"&gt;&lt;?php echo $i ?&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;?php }} ?&gt;
  &lt;/ul&gt;
  &lt;?php { ?&gt;
  </code></pre>
  
  <p>Since the default url contains already a query string, I had to modify the code a litte bit. I don't want the current site to have a link in the pagination. This gets me the number of the pagination query string:</p>
  
  <pre><code>$page_no = $_REQUEST['seite'];
  </code></pre>
  
  <p>I can then easily change the pagination links with a simple if-statement:</p>
  
  <pre><code>if ($i == $page_no) {...}?&gt;
  </code></pre>
  
  <p>Thanks again!</p>