创建重定向到另一个 URL 的 WordPress 页面 [英] Create WordPress Page that redirects to another URL

查看:25
本文介绍了创建重定向到另一个 URL 的 WordPress 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新的 WordPress 页面,它实际上是指向另一个站点的链接.目标是让页面显示在我的页面列表中,但实际上将网络用户发送到目标 URL.

I wanted to create a new WordPress page that is actually a link to another site. The goal is to have the page show up in a list of my pages, but actually send the web user to the target URL.

例如,假设我想要包含一个显示我的照片"但实际上将它们重定向到 Flickr 的页面.

For example, say I want to include a page that indicates "My Photos" but actually redirects them to Flickr.

我猜想实现此目的的一种方法是在 PHP 中使用带有重定向指令的自定义模板页面,但不幸的是,我是 PHP 的新手,不熟悉实现此目的的方法...

I'm guessing one way to accomplish this is by using a custom template page with a redirect instruction in PHP, but unfortunately I am a newbie to PHP and am not familiar with the way to accomplish this...

推荐答案

您可以通过两种方式来实现,这两种方式都需要通过编辑您的模板文件来完成.

You can accomplish this two ways, both of which need to be done through editing your template files.

第一个是在导航中添加一个 html 链接,只要您希望它显示.

The first one is just to add an html link to your navigation where ever you want it to show up.

第二个(我猜,你正在寻找的)是创建一个新的页面模板,如果你有能力在你的主题/模板目录中创建一个新的 .php 文件,这并不是太困难.像下面的代码应该做的事情:

The second (and my guess, the one you're looking for) is to create a new page template, which isn't too difficult if you have the ability to create a new .php file in your theme/template directory. Something like the below code should do:

<?php /*  
Template Name: Page Redirect
*/ 

header('Location: http://www.nameofnewsite.com');
exit();

?>

模板名称是您想设置的任何内容,标题函数中的 url 是您希望将用户定向到的新 url.修改上面的代码以满足您的需要后,将其保存在您活动主题文件夹中的php文件中,以模板名称命名.因此,如果您将模板的名称保留为页面重定向",请将 php 文件命名为 page-redirect.php.

Where the template name is whatever you want to set it too and the url in the header function is the new url you want to direct a user to. After you modify the above code to meet your needs, save it in a php file in your active theme folder to the template name. So, if you leave the name of your template "Page Redirect" name the php file page-redirect.php.

保存后,登录您的 WordPress 后端,并创建一个新页面.如果您愿意,您可以向正文添加标题和内容,但需要注意的重要一点是,在右侧,应该有一个下拉选项供您选择要使用的页面模板,默认显示第一的.在该下拉列表中,应该有要使用的新模板文件的名称.选择新模板,发布页面,你应该是金色的.

After that's been saved, log into your WordPress backend, and create a new page. You can add a title and content to the body if you'd like, but the important thing to note is that on the right hand side, there should be a drop down option for you to choose which page template to use, with default showing first. In that drop down list, there should be the name of the new template file to use. Select the new template, publish the page, and you should be golden.

此外,您也可以使用正文编辑器下方的自定义字段部分动态执行此操作.如果您有兴趣,请告诉我,我可以将那个人的代码粘贴到新回复中.

Also, you can do this dynamically as well by using the Custom Fields section below the body editor. If you're interested, let me know and I can paste the code for that guy in a new response.

这篇关于创建重定向到另一个 URL 的 WordPress 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆