我只是記錄下來,因爲它讓我真的很難過,現在我和世界和平......至少這個世界。
欺瞞永久鏈接
如何使它讓你有多個URL去同一個頁面,使你的WordPress網站看起來像一個SAP。
含義的URL像
http://www.asdf.com
http://www.asdf.com/about
解析到相同的URL,然後用JS你可以用JavaScript做花哨的東西。
守則
使用add_rewrite_rule重寫URL添加到主頁頁面的部分。下面的腳本在我的函數文件中動態地寫入了高級自定義字段的規則,但這僅僅是爲了這個實現。
<?php
add_action('init', 'all_pages_home');
function all_pages_home()
{
add_rewrite_rule(
'home',
'index.php',
'top'
);
add_rewrite_rule(
'about-us',
'index.php',
'top'
);
add_rewrite_rule(
'about',
'index.php',
'top'
);
add_rewrite_rule(
'portfolio',
'index.php',
'top'
);
add_rewrite_rule(
'team',
'index.php',
'top'
);
add_rewrite_rule(
'our-team',
'index.php',
'top'
);
add_rewrite_rule(
'contact',
'index.php',
'top'
);
add_rewrite_rule(
'press',
'index.php',
'top'
);
// custom rewrites for all team members
// this accesses ACF and dynamically writes these out based on a field url_path
$team_members = get_post_meta(359, 'section_team', true);
if($team_members):
for($i = 0; $i < $team_members; $i++) {
$url_path = esc_html(get_post_meta(359, 'section_team_' . $i . '_url_path', true));
if($url_path <> ''):
add_rewrite_rule(
$url_path,
'index.php',
'top'
);
endif;
}
endif;
flush_rewrite_rules();
}
在JavaScript文件,你可以做的東西一樣
<script type="text/javascript">
var pathName = window.location.pathname;
var pathNameClean = replaceAll(pathName, '/', '');
var isTeamMember = true;
var arrSections = ['home','about-us','about','portfolio','team','contact','press'];
for (i = 0; i < arrSections.length; i++) {
if(arrSections[i] === pathNameClean){
isTeamMember = false;
break;
}
}
</script>
然後
<script type="text/javascript">
var anchorHref = '#' + pathNameClean;
$('html, body').stop().animate({
scrollTop: $(anchorHref).offset().top - 64
}, 1500, 'easeInOutExpo');
</script>
這將滾動到正確的位置在頁面現在
它得到有點古怪和混亂一次。
STEP 1:去你的永久鏈接。
將其設置爲張貼名
保存更改...
第2步:下載您的.htaccess文件。
STEP 3:更改固定鏈接爲純
4步:上傳你創建了.htaccsss文件。
重要!!!! 請勿在您的網站上更新您的固定鏈接!
我試過了。我記得在路由方面有一些其他的事情。它有點像SAP。 add_rewrite_rule( '約', '的index.php', '頂部' );帶你到主頁,但我需要它去/關於但顯示主頁。它很奇怪,它在開發中起作用。我沒有在服務器上的東西....只是不記得這是什麼... – pelicanpaul
好吧,我不能肯定呢。在一個簡單的網站上,我使用相同的代碼。我不知道還有什麼可能導致它甚至在保存永久鏈接之後不起作用。 – Matt