• Resolved pensandpencils

    (@pensandpencils)


    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 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter pensandpencils

    (@pensandpencils)

    Thread Starter pensandpencils

    (@pensandpencils)

    That second bit came out odd it looks like this:

    <?php echo $before_widget; ?>
    			<?php echo $before_title . $title . $after_title; ?>
    			<ul>
    			<?php  while ($r->have_posts()) : $r->the_post(); ?>
    			<li><a class="<?php if ( the_ID() ); ?>" href="<?php the_permalink() ?>"><span><?php if ( get_the_title() ) the_title(); else the_ID(); ?></span> </a></li>
    			<?php endwhile; ?>
    			</ul>
    		<?php echo $after_widget; ?>
    Thread Starter pensandpencils

    (@pensandpencils)

    Well I figure it out, if anyones interested and wants to knwo how to do it.

    I found the info in the classes.php which is really obvious when you think about it….on line 578

    I changed it to this:

    $output .= $indent . '<li class="' . $css_class . '"><a class="menu' . ($page->ID) . '" href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . '<span>' . apply_filters('the_title', $page->post_title) . '</span></a>';

    So that the link has a span tag around it and the link itself has a dynamic class which relates to the specific page.

    Hopefully this will help someone in the future who really likes messing around with things….

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a link class to Page widget’ is closed to new replies.