Add a link class to Page widget
-
Hi there,
This is a really specific issue and I hope someone can help me.
I want to give the links in the Page widget a class and the word within the a tags an italics or span tag. This is purely so that I can use a little CSS to add rollover images to the link background.
I’ve been able to change the title of the list and the list that the widget is within but not the actual page widget list itself.
I’ve looked into the widgets.php file and have been able to do exactly this to the Latest Post widget but for the life of me I can’t find how to do this in the Pages widget as there doesn’t seem to be any code that links directly to the Page titles….
function wp_widget_pages( $args ) {
extract( $args );
$options = get_option( ‘widget_pages’ );$title = empty( $options[‘title’] ) ? __( ‘Pages’ ) : apply_filters(‘widget_title’, $options[‘title’]);
$sortby = empty( $options[‘sortby’] ) ? ‘menu_order’ : $options[‘sortby’];
$exclude = empty( $options[‘exclude’] ) ? ” : $options[‘exclude’];if ( $sortby == ‘menu_order’ ) {
$sortby = ‘menu_order, post_title’;
}$out = wp_list_pages( array(‘title_li’ => ”, ‘echo’ => 0, ‘sort_column’ => $sortby, ‘exclude’ => $exclude) );
if ( !empty( $out ) ) {
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>-
<?php echo $out; ?>
<?php echo $after_widget; ?>
<?php
}
}function wp_widget_pages_control() {
$options = $newoptions = get_option(‘widget_pages’);if ( $_POST[‘pages-submit’] ) {
$newoptions[‘title’] = strip_tags(stripslashes($_POST[‘pages-title’]));$sortby = stripslashes( $_POST[‘pages-sortby’] );
if ( in_array( $sortby, array( ‘post_title’, ‘menu_order’, ‘ID’ ) ) ) {
$newoptions[‘sortby’] = $sortby;
} else {
$newoptions[‘sortby’] = ‘menu_order’;
}$newoptions[‘exclude’] = strip_tags( stripslashes( $_POST[‘pages-exclude’] ) );
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option(‘widget_pages’, $options);
}
$title = attribute_escape($options[‘title’]);
$exclude = attribute_escape( $options[‘exclude’] );
?>That appears to be where the details are – but I can’t figure it out…
For an idea of what I’m talking about heres what I did with the Latest Post code:
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>-
<?php while ($r->have_posts()) : $r->the_post(); ?>
- ” href=”<?php the_permalink() ?>”><span><?php if ( get_the_title() ) the_title(); else the_ID(); ?></span>
<?php endwhile; ?>
<?php echo $after_widget; ?>
I know thats very different in the way its organise but hopefully that shows you what I mean.
Thanks in advance.
MA
- The topic ‘Add a link class to Page widget’ is closed to new replies.