Im using the the following PHP to display a number of widgets in my WordPress theme:
<?php
// A sidebar for widgets, just because.
if ( is_active_sidebar( 'primary-widget-area' ) ) : ?>
<ul>
<?php dynamic_sidebar( 'primary-widget-area' ); ?>
</ul>
<?php endif; ?>
Basically each widget in the <ul>
comes out as a list item. I want to be able to add a class to the last list item in the list.
Is it possible for me to do this with wordpress/php?
Ended up using this function.
http://wordpress.org/support/topic/how-to-first-and-last-css-classes-for-sidebar-widgets?replies=1
I once coded that wordpress adds a first and last classname to the first and last widget, you can find the code in the ticket.
However per CSS you should be able to address the last item by using the
:last-child
CSS selector (all browsers but not IE 5.5 – IE 8). So probably this already solves your issue.If you want to add a custom class for first or last widget inner sidebar.
You can using action hook “init”
my blog: http://colourstheme.com/2015/03/add-class-to-first-and-last-widget/