我想在第一个子页面上重定向用户。
例如有父页面:页面 A 它有 2 个子页面:child1 和 child 2
当用户单击页面 A 时,将用户重定向到子 1 页面
重定向插件太多,无法将父级重定向到手动设置的子级 1。我想要这个动态
是否可以以编程方式重定向第一个子页面上的父页面?
下面的方法就像一个魅力。 (http://www.wprecipes.com/wordpress-page-template-to-redirect-to-first-child-page http://www.wprecipes.com/wordpress-page-template-to-redirect-to-first-child-page)
为了实现这个秘诀,您必须创建一个页面模板。创建一个新文件并将以下代码粘贴到其中:
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
exit;
}
}
?>
将文件保存在名称redirect.php 下,并将其上传到WordPress 安装的wp-content/themes/your-theme 目录。完成后,您可以使用页面模板。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)