我想知道是否存在一些简单的代码来到达我知道它的ID的页面,我想创建小输入(无论在模板中),人们可以很容易地从那里到达页面,如果他们知道它的页面ID (4数字ID更好记住-永久链接名称,你可能会出错。我有女孩的投资组合在wordpress - portfolio=pages x工作在俱乐部offers=posts,我希望女孩的投资组合可以很容易地找到ID(s),如果可能的话,在俱乐部的posts=jobs相同的最佳解决方案小4-5数字输入和sidebar.php - index.php等send=go按钮
发布于 2010-03-25 04:52:59
已解决!作品完美感谢这段代码的作者帮助我从上面的网站链接运行它,所以非常感谢两个人!感谢代码的真正作者和回答第一个问题.link文本的编辑
<?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 " ";
} 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“代码作者站点”
发布于 2010-03-23 15:05:30
我不知道这是不是你想问的,但是你可以使用id得到永久链接,比如如果你有一个页面的id,你就可以像这样生成永久链接,<?php echo get_permalink($page_or_post_id); ?>
。因此,无论何时获得页面或帖子$id,您都可以重定向或显示指向该页面/帖子的链接
https://stackoverflow.com/questions/2496618
复制相似问题