I'm converting a theme for wp, and I need the pages listed on top with span tags inside the links, is there a way to create a function like wp_list_pages() that will return the links with spans?
I'm converting a theme for wp, and I need the pages listed on top with span tags inside the links, is there a way to create a function like wp_list_pages() that will return the links with spans?
Unless you write one...
But wp_list_pages adds a class to every line (li) when it displays the list, isn't that enough for styling?
Hi, that would've worked, but I need the tag to be INSIDE the anchor tag, cause it's properties need to change on hover, and as far as I know, IE only supports :hover in a tags
can someone help me understand how the wp_list_pages() function works, so I can build a custom one?
anyone?
Everything that template tag puts out is an anchor (link), isn't it?
As for the function - you can find all the functions and references here: http://redalt.com/xref/trunk/nav.htm?index.htm
I already found the function, this is the code:
function wp_list_pages($args = '') {
parse_str($args, $r);
if ( !isset($r['depth']) )
$r['depth'] = 0;
if ( !isset($r['show_date']) )
$r['show_date'] = '';
if ( !isset($r['child_of']) )
$r['child_of'] = 0;
if ( !isset($r['title_li']) )
$r['title_li'] = __('Pages');
if ( !isset($r['echo']) )
$r['echo'] = 1;
$output = '';
// Query pages.
$pages = & get_pages($args);
if ( $pages ) {
if ( $r['title_li'] )
$output .= '<li class="pagenav">' . $r['title_li'] . '
<ul>';
// Now loop over all pages that were selected
$page_tree = Array();
foreach ( $pages as $page ) {
// set the title for the current page
$page_tree[$page->ID]['title'] = $page->post_title;
$page_tree[$page->ID]['name'] = $page->post_name;
// set the selected date for the current page
// depending on the query arguments this is either
// the createtion date or the modification date
// as a unix timestamp. It will also always be in the
// ts field.
if ( !empty($r['show_date']) ) {
if ( 'modified' == $r['show_date'] )
$page_tree[$page->ID]['ts'] = $page->post_modified;
else
$page_tree[$page->ID]['ts'] = $page->post_date;
}
// The tricky bit!!
// Using the parent ID of the current page as the
// array index we set the curent page as a child of that page.
// We can now start looping over the $page_tree array
// with any ID which will output the page links from that ID downwards.
if ( $page->post_parent != $page->ID)
$page_tree[$page->post_parent]['children'][] = $page->ID;
}
// Output of the pages starting with child_of as the root ID.
// child_of defaults to 0 if not supplied in the query.
$output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false);
if ( $r['title_li'] )
$output .= '</ul>
';
}
$output = apply_filters('wp_list_pages', $output);
if ( $r['echo'] )
echo $output;
else
return $output;
}
I just can't figure out what i need to edit to make it put spans within the anchor tags.
anyone?
Scroll down a bit in template_functions_post.php to the _page_level_out() function, and you'll find this line:
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>';
That's where you want to slip in your span element.
Thanks a million!!! :)
This topic has been closed to new replies.