WordPress.org

Ready to get started?Download WordPress

Forums

Getting the ID From The Pages with wp_list_pages (3 posts)

  1. chaseman
    Member
    Posted 3 years ago #

    I want the user to be able to exclude pages from the navigation bar by simply ticking them off.

    I've created a list off all the menu items with a checkbox next to them like this:

    echo "<form method='POST' action=''>";
    wp_list_pages(array("link_before" => "<input type='checkbox' name='radio' value='$post_id' />", "title_li" => ""));
    echo "<input type='submit' name='radio_submit' />
    </form>";

    Now I need to be able to somehow have the page id inside the value of the checkbox. So when the user hits submit then the page id's get inserted into the $exclude variable in the navigation bar so the pages get excluded.

    Any ideas how I can fetch the id's from the generated list of navi items in the admin panel?

  2. chaseman
    Member
    Posted 3 years ago #

    I figured that the wp_list_pages function has a $current_page variable.

    Is there any way I could fetch it out of it?

    global $wp_query;
    		if ( is_page() || is_attachment() || $wp_query->is_posts_page )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
  3. chaseman
    Member
    Posted 3 years ago #

    I managed to do it this way by following an example in the documentation:

    <form method='POST' action=''>
    <select name="page-dropdown">
     <option value="">
    <?php echo attribute_escape(__('Select page')); ?></option>
     <?php
      $pages = get_pages();
      foreach ($pages as $pagg) {
      	$option = '<option value="'. $pagg->ID .'">';
    	$option .= $pagg->post_title;
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>
    <input type='submit' name='drop_submit' />
    </form>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.