开发者

How can I code Wordpress page in Drop Down List?

开发者 https://www.devze.com 2023-01-12 10:10 出处:网络
How can I 开发者_开发百科do code the wordpress page into dropdown list something like this Page 1

How can I 开发者_开发百科do code the wordpress page into dropdown list something like this Page 1 Page 2 Page 3

and then when I click submit it goes to the selected page.. .thank you so much guys in advance.. .

-idontknowhow


Use get_pages to fech all the pages under the system, there's an example to do exactly what you want:

<select name="page-dropdown"
    onchange='document.location.href=this.options[this.selectedIndex].value;'> 
    <option value=""><?php echo attribute_escape(__('Select page')); ?></option> 
    <?php 
        $pages = get_pages(); 
        foreach ($pages as $pagg) {
            $option = '<option value="'.get_page_link($pagg->ID).'">';
            $option .= $pagg->post_title;
            $option .= '</option>';
            echo $option;
        }
    ?>
</select>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号