WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Exclude links from certain pages using wp_list_pages() (5 posts)

  1. David Gard
    Member
    Posted 2 years ago #

    Hey all,

    Does anybody know if there is any easy way of excluding a link from a page using wp_list_pages()?

    I have a page that has several children, so I want them displayed when users hover over the parent - trouble is, the parent will alway contain no data but allows people to link to it.

    Thanks.

  2. Winifred
    Member
    Posted 2 years ago #

    You can exclude certain pages using the page ID, so like:

    <ul>
      <?php wp_list_pages('exclude=17,38' ); ?>
    </ul>

    I hope this helps. You can find more information here: http://codex.wordpress.org/Function_Reference/wp_list_pages

  3. David Gard
    Member
    Posted 2 years ago #

    Thanks Winifred, but I wasn't looking to exclude certain pages, mearly to make it so that the link to them did not work. I haven't found an *easy* way, but creating a custom Walker (below) and grabbing the pages like this works -

    /** Get the pages to display in the nav */
    $list_page_args = array(
    	'depth' => 2,
    	'echo' => 0,
    	'exclude' => $exclude,
    	'no_link' => array(8,9,10,170),
    	'title_li' => '',
    	'walker' => new Walker_Custom_Page
    );
    $pages = wp_list_pages($list_page_args);

    Custom walker in functions.php - in this Paste Bin

  4. Winifred
    Member
    Posted 2 years ago #

    Oooh, apologies :) Glad you found a solution anyhow.

  5. David Gard
    Member
    Posted 2 years ago #

    No worries - that's the trouble with text, so hard to get context across. As soon as I pressed 'Post' I thought someone would interpret it that way!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.