Forgive me for saying so but IMHO this is an exceptionally interesting question and one which is of wide application. It is also similar to one I asked a while ago and received no answer to. Without hijacking the thread but to put more meat on it I would love to know where the widgets are defined, including get pages, and where the functions in the widgets are set up. Where I am really headed is that I would like functions (a) to return plain unadorned links and (b) to have the option of adding my markup like the OP. In my case I would like to add an IE conditional at the critical point. I hope someone can point us in the right direction.
@dstn
Try using wp_list_pages to get your list of pages. This example will assign all page titles to the $pages array.
$pages = wp_list_pages('depth=-1&echo=1&hierarchical=0&sort_column=post_title&title_li=');
`
@root
The widget code is in wp-includes/widgets.php and does make use of the template tag, wp_list_pages()
If fact, dstn could use the code from widgets.php as an example also.
Thread Starter
dtsn
(@dtsn)
Hi MichealH,
Thanks for replying, how do i get the link to the pages. I know that i could just use <?php echo $pages ?> to give me the list of pages, but how do i get the link to those pages.
Thanks
Daniel
<?php
$pages = wp_list_pages('depth=-1&echo=1&hierarchical=0&sort_column=post_title&title_li=');
if ( ! empty($pages) ) {
foreach ($pages as $page) {
echo $page;
}
}
?>
is one possibility.
Thread Starter
dtsn
(@dtsn)
Sorry i may be a bit stupid, but i just don’t see how this would work. This would just produce the same thing as wp_list_pages, how do i get the links and page titles from it?
e.g. i need to have <li><a href="link"><span>page name</span></a></li>
Could i use echo $page[‘title’]?
Thanks
Daniel
There’s this also:
<?php
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.post_title ASC";
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php if ($pageposts): ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></p>
<?php endforeach; ?>
<?php else : ?>
Not Found
<?php endif; ?>
Thread Starter
dtsn
(@dtsn)
Thanks great thanks! 😀
You wouldn’t happen to know how i could tell which page i am on so i could change the class accordingly?
Thanks
Daniel
Mh. Thanks a lot this is really useful. But are you sure they are still in widgets.php? I can’t find them. I thought maybe widgets.php called in the actual widgets from another file. Maybe?
Yes, wp-includes/widgets.php is where the built-in widgets are defined. Just look for the wp_list_pages text in that file for example.
Also, there is some widget ‘data’ kept in wp_options with an option_name like widget_pages.
That is great thanks. I am going to get right on this.
I wanted to do this too, and couldn’t find any information on it.
In the end, I had to edit the start_el() function in wp-includes/classes.php
Change the following (from about line 517):
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
To this:
$output .= $indent . '<li class="' . $css_class . '"><a 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>';
Of course, this will always add span tags any time wp_list_pages is called. And you’ll have to remember that you’ve done this hack the next time you upgrade…
Eureka. The Holy Grail. A big up to analogpanda for his discovery of where that dang thing is edited. Now we are rocking. Is this the end for Son of Suckerfish? 🙂
Just for completeness, my above hack was done with WP 2.2.1
Let’s hope that 2.3 (or even 2.2.2?) has a little more flexibility in this regard.
I’m actually a little surprised they wouldn’t just use “the loop” – would probably end up with a more elegant solution than my hacky method… But I’m not a real php dev – maybe they have their reasons!