wordpress调用指定ID页面的链接

在WordPress中,如果你想调用一个指定ID的页面链接,可以使用以下几种方法:

方法一:使用页面ID

你可以直接使用页面的ID来生成链接。例如,如果你想链接到ID为123的页面,可以使用以下代码:

复制代码
<a href="<?php echo get_permalink(666); ?>">访问页面</a>

这里的get_permalink()函数会返回指定页面ID的永久链接。

方法二:使用页面别名(Slug)

如果你的页面有一个别名(slug),你也可以使用这个别名来生成链接。例如,如果页面的slug是about-us,可以使用以下代码:

复制代码
<a href="<?php echo get_permalink(get_page_by_path('about-us')->ID); ?>">访问关于我们页面</a>

这里get_page_by_path()函数会根据页面的slug找到对应的页面对象,然后get_permalink()函数会返回该页面的永久链接。

通过以上方法,你可以灵活地在WordPress中调用指定ID页面的链接。

原文

https://www.jianzhanpress.com/?p=8364

相关推荐
VIP_CQCRE2 天前
用 Ace Data Cloud 自动发布 WordPress 文章:把 SEO 内容站变成长期增长资产
ai·自动化·seo·wordpress·acedatacloud
2601_965798476 天前
Renovate Theme Setup: Fast Contractor & Construction Site Architecture
theme·wordpress
2601_965798478 天前
Salient Theme Setup Guide for Fast Creative WordPress Sites
数据库·web3·php·wordpress
2601_9657984710 天前
Boutique Business Consulting WordPress Architecture & SEO Setup
android·theme·wordpress
2601_9657984711 天前
Plastic Surgery Clinic Web Setup: Deploying Rejuvita WordPress
php·theme·wordpress
2601_9657984711 天前
Contractor Web Setup: Deploying Bathrooms & Kitchens Theme Fast
前端·web3·php·wordpress
e6zzseo18 天前
wordpress独立站seo怎么做才有效
seo·wordpress·独立站·内容优化·外链建设
Web极客码20 天前
如何让用户订阅WordPress评论?提升用户互动的有效策略
运维·服务器·wordpress
fobwebs20 天前
Wordpress Xstore 主题安装Elementor Pro 后找不到某些Elements 组件的解决方法
element·wordpress·form·xstore·pro elements·elementor pro
代龙涛21 天前
WordPress sidebar.php 侧边栏开发教程
开发语言·php·wordpress