用PHP链接WordPress页面的最佳方式是什么?考虑到我将页面从本地服务器移动到实时服务器,再移动到另一个URL?
<a href="/wordpress/services" title="Read More" class="yellowButton">Read more</a>
如何用链接到WordPress页面的PHP替换此代码。/wordpress/services
用PHP链接WordPress页面的最佳方式是什么?考虑到我将页面从本地服务器移动到实时服务器,再移动到另一个URL?
<a href="/wordpress/services" title="Read More" class="yellowButton">Read more</a>
如何用链接到WordPress页面的PHP替换此代码。/wordpress/services
$id
, 使用get_permalink()
:<?php $permalink = get_permalink( $id ); ?>
如果您知道该页面,请从$slug中永久链接$slug
, 例如/about
(包括层次结构,例如/about/work
), 使用get_page_by_path()
确定页面的步骤$id
, 然后使用get_permalink()
.<?php
$page_object = get_page_by_path( $slug );
$page_id = $page_object->ID;
$permalink = get_permalink( $page_id );
?>
如果您知道该页面,请从$title永久链接该页面$title
, 例如“一些随机页面名称”,使用get_page_by_title()
, 然后使用get_permalink()
:<?php
$page_object = get_page_by_title( $title );
$page_id = $page_object->ID;
$permalink = get_permalink( $page_id );
?>
要按名称查找它们吗?如果是,那么您可以
<a href="<?php echo site_url(\'/services\'); ?>"> Services </a>
如果要硬编码“/页面名称”,可以使用home_url(\'/wordpress/services\') 使用esc\\u url()函数清理url-它将始终为您提供主页的完整url(本地或实时)
<a href="<?php echo esc_url( home_url( \'/wordpress/services\' ) ); ?>"
title="Read More" class="yellowButton">
Read more
</a>
您可以使用短代码将域名插入内部链接,然后只需在末尾添加页面url,例如[域名]/页面名称。
将此代码添加到子主题函数中。php,一切就绪!
//add shortcode that displays current site name
function domain_name(){
$currentDomain = "yoursite.com";
return $currentDomain;
}
add_shortcode(\'domain_name\', \'domain_name\');
我已经在多个现场网站上测试过,它似乎工作得很好。希望这就是你要找的!
我正在使用get_pages 函数显示自定义帖子类型中的所有页面,如下所示:<?php $args = array( \'post_type\' => \'pcct_product\', \'sort_column\' => \'post_title\', \'menu_order\' =>