wordpress 显示所选项目

发布于 2024-10-02 12:42:30 字数 778 浏览 1 评论 0原文

我正在使用 query_posts 拉取某些页面来填充下拉菜单。

让我们假设列表填充以下字段

option1, option2, option3 and option4

现在,如果我选择了 option3 并且我的页面更改为此,我如何将其显示为 selectedIndex?

<select name="speedC" id="speedC"
    onchange='document.location.href=this.options[this.selectedIndex].value;'> 
    <option value="">
    <?php echo attribute_escape(__('V&auml;lj en fr&aring;n listan')); ?></option> 
    <?php 
    $pages = get_pages('include=11,13,15,17,38'); 
    foreach ($pages as $pagg) {
        $option = '<option value="'.get_page_link($pagg->ID).'">';
        $option .= $pagg->post_title;
        $option .= '</option>';
       echo $option;
    } ?>
</select>

I am pulling certain pages using query_posts to populate a dropdown menu.

lets assume the list populate the following fields

option1, option2, option3 and option4

Now if I have selected option3 and my page changes to this, how do I display this as the selectedIndex?

<select name="speedC" id="speedC"
    onchange='document.location.href=this.options[this.selectedIndex].value;'> 
    <option value="">
    <?php echo attribute_escape(__('Välj en från listan')); ?></option> 
    <?php 
    $pages = get_pages('include=11,13,15,17,38'); 
    foreach ($pages as $pagg) {
        $option = '<option value="'.get_page_link($pagg->ID).'">';
        $option .= $pagg->post_title;
        $option .= '</option>';
       echo $option;
    } ?>
</select>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2024-10-09 12:42:30

你想使用Wordpress函数is_page(),

is_page('id')

其中“id”是你已经获取的id。有关详细信息,请查看 wordpress Codex 站点

编辑:
我不太确定这里的语法,但类似这样的东西可能会让您启动并运行:

<select name="speedC" id="speedC"
onchange='document.location.href=this.options[this.selectedIndex].value;'> 
<option value="">
<?php echo attribute_escape(__('Välj en från listan')); ?></option> 
<?php 
$pages = get_pages('include=11,13,15,17,38'); 
foreach ($pages as $pagg) {

    $option = '<option value="'.get_page_link($pagg->ID).'"';
    if(is_page($pagg->ID)){
       $option .= "SELECTED "
    }
    $option .= ">".$pagg->post_title;
    $option .= '</option>';
   echo $option;
} ?>
</select>

You want to use the Wordpress function is_page()

is_page('id')

Where 'id' is the id that you already have fetched. For more information, check the wordpress codex site

EDIT:
I'm not too sure about the syntax here, but something like this might get you up and running:

<select name="speedC" id="speedC"
onchange='document.location.href=this.options[this.selectedIndex].value;'> 
<option value="">
<?php echo attribute_escape(__('Välj en från listan')); ?></option> 
<?php 
$pages = get_pages('include=11,13,15,17,38'); 
foreach ($pages as $pagg) {

    $option = '<option value="'.get_page_link($pagg->ID).'"';
    if(is_page($pagg->ID)){
       $option .= "SELECTED "
    }
    $option .= ">".$pagg->post_title;
    $option .= '</option>';
   echo $option;
} ?>
</select>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文