Add Dynamic Wrapper div to a Row I have buttons below a slideshow I have created. I want them to be centered whether there be 1, 2, etc. I'm looking to have a wrapper div surrounding them with a class name of "button-count-x" (x being number of buttons). I've tried using a 'foreach' loop and counting the number of $row's, but that is not working.

Note: I am using the "Views Slideshow" module and am using the view's respective 'views-view.tpl.php' file.

&lt;?php $count = 0; ?&gt;

&lt;?php foreach ($fields as $id =&gt; $field): ?&gt;
&lt;?php if (!empty($field-&gt;separator)): ?&gt;
&lt;?php $count ++; ?&gt;
&lt;?php print $field-&gt;separator; ?&gt;


  

&lt;div class = "test"&gt;&lt;?php print $count; ?&gt;&lt;/div&gt;

&lt;?php print $field-&gt;wrapper_prefix; ?&gt;
&lt;?php print $field-&gt;label_html; ?&gt;
&lt;?php print $field-&gt;content; ?&gt;
&lt;?php print $field-&gt;wrapper_suffix; ?&gt;
&lt;?php endforeach; ?&gt;
that's not much to go on, so I'll assume that the module generates one button per slide in the slideshow, and you want them centered underneath the image area ?

It's hard to know without the markup, but a couple of css selectors should do the trick.

for the containing div, if it has an id, or a uniquely addressable class, try something like this:

#container {
    width: 100%;
    text-align: center;
}


and if the button divs or whatever have no convenient id or class, address them something like this:

#container &gt; div {
    display: inline-block;
}


I think you may be better off sticking to css. Post the relevant rendered html, and perhaps we can help.