I am using this code to display a list of child pages of a parent:
<?php
global $post; // Setup the global variable $post
if ( is_page() && $post->post_parent ) {
// Make sure we are on a page and that the page is a parent.
$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
} else {
$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
}
if ( $kiddies ) {
echo '<ul class="secondary">';
echo $kiddies;
echo '</ul>';
}
I want to be able to customise the anchor text of the link. e.g. if the child page name is "blue" I want to append "widget" to the end to make the anchor "blue widget".
Can anyone help?
Thanks
I am using this code to display a list of child pages of a parent:
<?php
global $post; // Setup the global variable $post
if ( is_page() && $post->post_parent ) {
// Make sure we are on a page and that the page is a parent.
$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
} else {
$kiddies = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
}
if ( $kiddies ) {
echo '<ul class="secondary">';
echo $kiddies;
echo '</ul>';
}
I want to be able to customise the anchor text of the link. e.g. if the child page name is "blue" I want to append "widget" to the end to make the anchor "blue widget".
Can anyone help?
Thanks
You can use the_title
filter. Just remember to remove it after wp_list_pages()
otherwise it will effect everywhere on the site like in menu, main title, search results etc.
Example:-
add_filter('the_title', 'my_custom_title');
wp_list_pages();
remove_filter('the_title', 'my_custom_title');
function my_custom_title($current_title) {
if ($current_title == 'blue') {
$current_title = $current_title . ' widget';
}
return $current_title;
}