开发者

Wordpress: How to be redirected to the page when inserting it's page ID into numeric form input with click button SEND?

开发者 https://www.devze.com 2022-12-23 15:45 出处:网络
I would like to know if there\'s exists some simple code to get to the page i know its ID , I would like to create small input (no matter where in templates)from where the people can easily get to the

I would like to know if there's exists some simple code to get to the page i know its ID , I would like to create small input (no matter where in templates)from where the people can easily get to the page if they know it's page ID (4numeric ID is better to remember - permalink name you can mistake . I have the girls portfolio in wordpress - portfolio=pages x jobs in clubs offers=posts , I would like开发者_如何学编程 the girls portfolios to be easily findable by ID(s) , if possible the same for the posts=jobs in clubs The best solution little 4-5numeric input and send=go button in sidebar.php - index.php etc


i take something like this in here source. Maybe it can help, though i don't know if its working

`

function baka_show_form_redirect() {
      $form_search =’<form action="" method="post" name="redirect_to_post_id" class="description" style="color:#fff;font-size:10px;text-align:left;position:fixed;top:40px;">
      <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 … &lt;a href =’" . $_redirect_to . "’&gt;Back&lt;/a&gt;");
          }
    }

} }

add_action(‘wp_head’, ‘baka_show_form_redirect’); add_action(‘init’, ‘baka_validasi_post_id’); ?>

`


Resolved !!! works perfect thanks to the author of this code who helped me to make it run from the website link above , so Thanks a lot to both men !!!Thanks to real author of the code and the editor who answered the first question .[link text][1]

<?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'); 
?>

[1]: http://www.bakawan.com/log/howto-wordpress-redirect-based-on-post-id/comment-page-1/#comment-6654"Code author's site"


I don't know if this is what you are asking, but you can get permalink using id i.e. if you have a pages' id the you can generate permalink like so, <?php echo get_permalink($page_or_post_id); ?> . So whenever you get $id of a page or post you can redirect or show link to that page/post

0

精彩评论

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