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.

<?php $count = 0; ?>

<?php foreach ($fields as $id => $field): ?>
<?php if (!empty($field->separator)): ?>
<?php $count ++; ?>
<?php print $field->separator; ?>
<div class = "test"><?php print $count; ?></div>

<?php print $field->wrapper_prefix; ?>
<?php print $field->label_html; ?>
<?php print $field->content; ?>
<?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>
  • Post a code that fails for you. We can help, but we can't write things for you from scratch.
    – Mołot
    Jun 25, 2013 at 15:00

1 Answer 1


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 > div {
    display: inline-block;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.