Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] wp_list_pages to anchor

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26314

    Hi, I´m using this code to list only the subpages,

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    but I need them to go to a specific anchor call #menu

    Any Help?

    thanks

    #64965

    It’s not straightforward to do this as it involves using a filter to modify the page link.

    Code:
    // Place this function in your theme’s functions.php
    function add_hash($link) {
    // this code adds a hash tag to the end of the link
    return $link . ‘#menu’;
    }

    Then in your theme use this:

    Code:
    add_filter(‘page_link’, ‘add_hash’);

    // .. your code to list subpages here

    remove_filter(‘page_link’, ‘add_hash’);

    #64993

    Nice It really works fine, thank you a lot.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.