WordPress.org

Ready to get started?Download WordPress

Forums

Page.php ---> problem Showing Current Page in select! (2 posts)

  1. M Szatkowski
    Member
    Posted 4 years ago #

    Hi
    I want to display current page [selected=selected] and parent page [selected=selected] in select form.

    So I've put in page.php for current parent page:

    <form>
    <select>
    	<?php
    	    $include_page_ids = array('7','8','11','12','13','14','15','16','17','18','19','21','23','24','25'); //also the order of appearance
    	    for ($i = 0;$i < count($include_page_ids);$i++) {
    		$args = array('title_li'=>'','include' => $include_page_ids[$i],'link_before'=>'<option>','link_after'=>'</option>');
    		wp_list_pages( $args );
    		}
    
    	?>
    	</select>
    </form>

    and for current page:

    <form>
    
    		<?
    if(wp_list_pages('child_of='.$post->ID.'&echo=0&exclude=2')) {
    echo "<p>";
    wp_list_pages('title_li=&child_of='.$post->ID.'&exclude=2'.'link_before= <option selected=selected>'.'link_after=</option>');
    echo "</p>";
    }
    elseif(get_the_title($post->post_parent) != the_title(' ' , ' ',false)) {
    echo "<select>";
    wp_list_pages('child_of='.$post->post_parent.'&title_li=&exclude=2'.'link_before=> <option>'.'link_after=></option>');
    echo "</select>";
    } ?>
    
    </form>

    and the parent page seems to almost work [doesn't display selected=selected] while current page does not at all...

    Changing the select filed should change the url as well...

    Do you have an idea how to work it out?

    Thanks!

    Marius

  2. s_ha_dum
    Member
    Posted 4 years ago #

    In the first case, I don't think you can do that with wp_list_pages. You need to conditionally insert 'selected="selected"' and I don't know of any way to do that with wp_list_pages, although there is a wp_list_pages hook that you might be able to hook some regex to.

    In the second case, it looks like you are missing an ampersand before the 'link_before=' and before the 'link_after='. I confess, however, that I really hate that 'url get string' style parameter mechanism. It confuses me and I never use it, so I may have missed something.

Topic Closed

This topic has been closed to new replies.

About this Topic