Wordpress:插入页面时如何重定向到页面';使用“发送”按钮将页面ID转换为数字形式输入?

Wordpress:插入页面时如何重定向到页面';使用“发送”按钮将页面ID转换为数字形式输入?,wordpress,Wordpress,我想知道是否存在一些简单的代码来访问页面我知道它的ID,我想创建一些小的输入(无论在模板中的什么地方),如果人们知道它的ID,他们可以很容易地访问页面(4最好记住数字ID-permalink name你可能会弄错。我在wordpress中有女孩的投资组合-投资组合=页面x俱乐部中的工作提供=帖子,我希望女孩的投资组合可以通过ID轻松找到,如果可能的话,帖子=俱乐部中的工作也是如此 最佳解决方案sidebar.php-index.php等中的4-5数字输入和send=go按钮我不知道这是否是您所要

我想知道是否存在一些简单的代码来访问页面我知道它的ID,我想创建一些小的输入(无论在模板中的什么地方),如果人们知道它的ID,他们可以很容易地访问页面(4最好记住数字ID-permalink name你可能会弄错。我在wordpress中有女孩的投资组合-投资组合=页面x俱乐部中的工作提供=帖子,我希望女孩的投资组合可以通过ID轻松找到,如果可能的话,帖子=俱乐部中的工作也是如此
最佳解决方案sidebar.php-index.php等中的4-5数字输入和send=go按钮

我不知道这是否是您所要求的,但您可以使用id获得永久链接,也就是说,如果您有页面id,您可以像这样生成永久链接,
。因此,无论何时您获得页面或帖子的$id,您都可以重定向或显示指向该页面的链接/post

我在这里带了这样的东西。也许它能帮上忙,尽管我不知道它是否有效

` }

函数baka_validasi_post_id(){ 如果($\u POST['POST\u id']&&&$\u POST['POST\u id']!=){ $post_id=$_post['post_id']; if(absint($post_id)){//必须是整数而不是负的

<?php
}

function baka_show_form_redirect() {
      $form_search ='<form action="" method="post" name="redirect_to_post_id">
      <h4>Theme Feature</h4>
      <ol>
          <li><label for="post_id" title="Put numerical value of existing post ID">Redirect to ID (numerical) : </label>
          <input name="post_id" type="text" maxlength="4" class="description"
              style="width:30px;display:inline;border:none;color:#000" /></li>
      </ol>
        <input name="_redirect_to" type="hidden" value="' . get_permalink() . '" />
      </form>';

      echo $form_search;
}

function baka_validasi_post_id() {
    if( $_POST[ 'post_id' ] && $_POST[ 'post_id' ] != '' ) {
          $post_id = $_POST[ 'post_id' ];
          if (absint($post_id)) { //must be integer and not negative

              $url = get_permalink($post_id);

              if ($url) {
                  wp_redirect($url); echo "&nbsp;";
              } else {
                  $_redirect_to = $_POST[ '_redirect_to' ];
                  wp_die("ID can not be found … <a href ='" . $_redirect_to . "'>Back</a>");
              }
        }
  }
}

add_action('wp_head', 'baka_show_form_redirect');
add_action('init', 'baka_validasi_post_id'); 
?>
} }

添加动作(“wp_头”、“baka_显示形式重定向”); 添加动作('init','baka_validasi_post_id');
?>`

已解决!!!非常感谢此代码的作者帮助我从上面的网站链接运行此代码,所以非常感谢这两个人!!!感谢代码的真正作者和回答第一个问题的编辑。[链接文本][1]



[1] :“代码作者的网站”

这正是我所想的!!!,非常感谢这段代码,但不幸的是它在Wordpress 2.9.2中不起作用:(,我需要在哪里插入这段代码?直接插入模板或functions.php的某些部分?没有解释在哪里插入它。但我很高兴至少你的代码我可以更好地解释这个问题。另外,这段代码只适用于帖子,不适用于页面。我也尝试将它放在header.php的header和it之间,它向我展示了错误。你应该把它放在函数中。PHP尝试使用它后,我知道它可以搜索帖子和页面。顺便说一句,什么样的错误?如果我知道我会回答,但如果太难,也许你应该咨询作者银行以获得你的回复。乔,我没有注意到你的答案,我是新来的,所以我没有看到有人在回复,也没有顺便说一句,ify函数在这里工作有很大的延迟。代码正在工作,作者帮助我,我将代码发布在此页面上。再次感谢您的帮助非常感谢您的评论,但我需要上面答案中的选项,当任何人都可以将页面ID插入一个小数字输入框中时,提交后的人可以重定向到页面(女孩档案页)容易(最好记住4个数字,而不是女孩的确切姓名(permalink)
          $url = get_permalink($post_id);

          if ($url) {
              wp_redirect($url); echo "&nbsp;";
          } else {
              $_redirect_to = $_POST[ '_redirect_to' ];
              wp_die("ID can not be found … &lt;a href =’" . $_redirect_to . "’&gt;Back&lt;/a&gt;");
          }
    }
<?php
}

function baka_show_form_redirect() {
      $form_search ='<form action="" method="post" name="redirect_to_post_id">
      <h4>Theme Feature</h4>
      <ol>
          <li><label for="post_id" title="Put numerical value of existing post ID">Redirect to ID (numerical) : </label>
          <input name="post_id" type="text" maxlength="4" class="description"
              style="width:30px;display:inline;border:none;color:#000" /></li>
      </ol>
        <input name="_redirect_to" type="hidden" value="' . get_permalink() . '" />
      </form>';

      echo $form_search;
}

function baka_validasi_post_id() {
    if( $_POST[ 'post_id' ] && $_POST[ 'post_id' ] != '' ) {
          $post_id = $_POST[ 'post_id' ];
          if (absint($post_id)) { //must be integer and not negative

              $url = get_permalink($post_id);

              if ($url) {
                  wp_redirect($url); echo "&nbsp;";
              } else {
                  $_redirect_to = $_POST[ '_redirect_to' ];
                  wp_die("ID can not be found … <a href ='" . $_redirect_to . "'>Back</a>");
              }
        }
  }
}

add_action('wp_head', 'baka_show_form_redirect');
add_action('init', 'baka_validasi_post_id'); 
?>