Добре. Ето вашия код. Просто отменям програмата по подразбиране на wordpress. Моля, фокусирайте се върху текста #header в този код.
Ако се притеснявате за този код. Така че можете да отидете на файл: ...wp-includes/post-template.php на ред 1238. Същият код, но имам добавяне на #header след get_permalink().
Надявам се това да помогне.
class WPSE_HasHeader_Custom_Walker extends Walker_Page {
function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
if ( $depth )
$indent = str_repeat("\t", $depth);
else
$indent = '';
extract($args, EXTR_SKIP);
$css_class = array('page_item', 'page-item-'.$page->ID);
if( isset( $args['pages_with_children'][ $page->ID ] ) )
$css_class[] = 'page_item_has_children';
if ( !empty($current_page) ) {
$_current_page = get_post( $current_page );
if ( in_array( $page->ID, $_current_page->ancestors ) )
$css_class[] = 'current_page_ancestor';
if ( $page->ID == $current_page )
$css_class[] = 'current_page_item';
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
$css_class[] = 'current_page_parent';
} elseif ( $page->ID == get_option('page_for_posts') ) {
$css_class[] = 'current_page_parent';
}
$css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
if ( '' === $page->post_title )
$page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
/** CHANGE LINK HERE **/
$output .= $indent . '<li class="' . $css_class . '"><a href="/bg' . get_permalink($page->ID) . '#header">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
if ( !empty($show_date) ) {
if ( 'modified' == $show_date )
$time = $page->post_modified;
else
$time = $page->post_date;
$output .= " " . mysql2date($date_format, $time);
}
}
}
wp_list_pages(array(
'sort_column' => 'menu_order',
'title_li' => '',
'echo' => 1,
'walker' => new WPSE_HasHeader_Custom_Walker()
));
Актуализирано:
Вторият начин: Благодаря Mere Development. Мисля, че това е същата идея с него, но е много по-просто във вашия случай. Като този:
$link = wp_list_pages(array(
'sort_column' => 'menu_order',
'title_li' => '',
'echo' => 0,
));
echo preg_replace('/<a(.*)href="/bg([^"]*)"(.*)>/', '<a$1href="/bg$2#header"$3>', $link);
person
christian Nguyen
schedule
30.04.2015