php 链接到内部页面 wordpress

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14047661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:30:59  来源:igfitidea点击:

link to internal page wordpress

phpwordpressfunctionhyperlink

提问by Ben

I'm a newbie to wordpress, I added a new page via dashboard, and I want to make a link to this page from the home page so I would love to know what function does that,

我是 wordpress 的新手,我通过仪表板添加了一个新页面,我想从主页创建一个指向该页面的链接,所以我很想知道这是什么功能,

I think it would be something like: >LINK

我认为它会是这样的:>LINK

Thanks in advance!!

提前致谢!!

回答by RRikesh

You could use

你可以用

<a href="<?php echo get_page_link( get_page_by_title( PAGE_NAME )->ID ); ?>">Link Title</a>

Where PAGE_NAMEis the page title you have set in the dashboard.

PAGE_NAME您在仪表板中设置的页面标题在哪里。

get_page_by_title()returns an object and we use get_page_by_title( PAGE_NAME )->IDto return the page ID of that page. Note that it is more consistent to rely on the page title (which you set yourself) against page ID (which is set by wordpress).

get_page_by_title()返回一个对象,我们get_page_by_title( PAGE_NAME )->ID用来返回该页面的页面 ID。请注意,根据页面 ID(由 wordpress 设置)依赖页面标题(您自己设置)更一致。

get_page_link()retrieves the permalink of that page ID you passed as parameter.

get_page_link()检索您作为参数传递的该页面 ID 的永久链接。

回答by djdy

You can simply link to the page in the HTML body of the home page. For example:

您可以简单地链接到主页的 HTML 正文中的页面。例如:

<a href="/index.php/your-page">your page</a>

<a href="/index.php/your-page">your page</a>

or

或者

<a href="index.php?page_id=###">your page</a>

<a href="index.php?page_id=###">your page</a>

Where ###, put the post ID.

在哪里###,放置帖子ID。

More examples

更多例子

Edit:

编辑:

If you are editing a template, and wish to obtain the permalink of the post using its ID, use get_permalink($id)

如果您正在编辑模板,并希望使用其 ID 获取帖子的永久链接,请使用 get_permalink($id)

More information about this function

有关此功能的更多信息

Edit 2:

编辑2:

Based on your comments, you have to switch the permalink format. In WP Admin, find Permalink Settings, and set them to /%postname%/

根据您的评论,您必须切换永久链接格式。在 WP Admin 中,找到 Permalink Settings,并将它们设置为 /%postname%/

Read more about these settings here

在此处阅读有关这些设置的更多信息