0
A
回答
2
嗨你好,它是由JS和ajax完成,只要你寫標題,它會發送標題與Ajax和變成永久鏈接,並獲得固定鏈接領域。我發現源代碼希望它能幫助你。
可溼性粉劑管理員/包括/ post.php中線1257
function get_sample_permalink_html($id, $new_title = null, $new_slug = null) {
$post = get_post($id);
if (! $post)
return '';
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
if (current_user_can('read_post', $post->ID)) {
$ptype = get_post_type_object($post->post_type);
$view_post = $ptype->labels->view_item;
}
if ('publish' == get_post_status($post)) {
$title = __('Click to edit this part of the permalink');
} else {
$title = __('Temporary permalink. Click to edit this part.');
}
if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
if ('' == get_option('permalink_structure') && current_user_can('manage_options') && !('page' == get_option('show_on_front') && $id == get_option('page_on_front'))) {
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
}
} else {
if (function_exists('mb_strlen')) {
if (mb_strlen($post_name) > 30) {
$post_name_abridged = mb_substr($post_name, 0, 14) . '…' . mb_substr($post_name, -14);
} else {
$post_name_abridged = $post_name;
}
} else {
if (strlen($post_name) > 30) {
$post_name_abridged = substr($post_name, 0, 14) . '…' . substr($post_name, -14);
} else {
$post_name_abridged = $post_name;
}
}
$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
$display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, urldecode($permalink));
$pretty_permalink = str_replace(array('%pagename%', '%postname%'), $post_name, urldecode($permalink));
$return = '<strong>' . __('Permalink:') . "</strong>\n";
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
$return .= '‎'; // Fix bi-directional text display defect in RTL languages.
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
}
if (isset($view_post)) {
if('draft' == $post->post_status) {
$preview_link = set_url_scheme(get_permalink($post->ID));
/** This filter is documented in wp-admin/includes/meta-boxes.php */
$preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_link), $post);
$return .= "<span id='view-post-btn'><a href='" . esc_url($preview_link) . "' class='button button-small' target='wp-preview-{$post->ID}'>$view_post</a></span>\n";
} else {
if (empty($pretty_permalink)) {
$pretty_permalink = $permalink;
}
$return .= "<span id='view-post-btn'><a href='" . $pretty_permalink . "' class='button button-small'>$view_post</a></span>\n";
}
}
/**
* Filter the sample permalink HTML markup.
*
* @since 2.9.0
*
* @param string $return Sample permalink HTML markup.
* @param int|WP_Post $id Post object or ID.
* @param string $new_title New sample permalink title.
* @param string $new_slug New sample permalink slug.
*/
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
return $return;
}
這是用於
可溼性粉劑管理員/ JS/post.js線706
js的// permalink
function editPermalink() {
var i, slug_value,
c = 0,
e = $('#editable-post-name'),
revert_e = e.html(),
real_slug = $('#post_name'),
revert_slug = real_slug.val(),
b = $('#edit-slug-buttons'),
revert_b = b.html(),
full = $('#editable-post-name-full');
// Deal with Twemoji in the post-name
full.find('img').replaceWith(function() { return this.alt; });
full = full.html();
$('#view-post-btn').hide();
b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
b.children('.save').click(function() {
var new_slug = e.children('input').val();
if (new_slug == $('#editable-post-name-full').text()) {
b.children('.cancel').click();
return false;
}
$.post(ajaxurl, {
action: 'sample-permalink',
post_id: postId,
new_slug: new_slug,
new_title: $('#title').val(),
samplepermalinknonce: $('#samplepermalinknonce').val()
}, function(data) {
var box = $('#edit-slug-box');
box.html(data);
if (box.hasClass('hidden')) {
box.fadeIn('fast', function() {
box.removeClass('hidden');
});
}
b.html(revert_b);
real_slug.val(new_slug);
$('#view-post-btn').show();
});
return false;
});
1
它使用AJAX。 當你寫這篇文章時,JS將標題發送到服務器,在那裏生成永久鏈接併發送回頁面。
+0
感謝您的信息:) –
1
永久鏈接不是「生成」的,對於使用永久鏈接,閱讀關於mod_rewrite。
該鏈接看起來像「寫你的帖子標題在這裏」是一個實際的文件,而不是。
該頁面會將您重定向到「posts.php」,那裏正在分析appendex,然後db調用正好與那些選項一起啓動。
像
"SELECT * FROM posts WHERE title LIKE `write-your-post-title-here`"
沒有JS,沒有AJAX。
JS用於「更新」鏈路的光學狀態。因此,如果您點擊編輯並更改帖子標題,JS會動態更新文本,您可以看到您實際輸入的內容。
+1
感謝您的信息:) –
相關問題
- 1. 404 on WordPress的帖子永久鏈接
- 2. 更改特定帖子的WordPress的永久鏈接
- 3. WordPress的:自定義帖子永久鏈接
- 4. 使用WordPress的永久鏈接沒有帖子
- 5. 爲特定頁面設置wordpress帖子的永久鏈接
- 6. WordPress的永久鏈接
- 7. WordPress的永久鏈接
- 8. WordPress的永久鏈接集
- 9. 如何更改codeigniter帖子永久鏈接爲WordPress
- 10. 在WordPress中使用帖子Meta永久鏈接
- 11. WordPress ||自定義帖子類型,永久鏈接和數字
- 12. WP生成錯誤的永久鏈接
- 13. Wordpress wp_list_pages()與永久鏈接
- 14. 永久鏈接Ajax Issue Wordpress
- 15. 在php程序中由wordpress生成的錯誤永久鏈接
- 16. 如何更改單個帖子永久鏈接的默認結構生成?
- 17. 生成表單永久鏈接
- 18. WordPress的永久鏈接問題 - 額外的「index.php」在漂亮的永久鏈接
- 19. nginx的WordPress的漂亮永久鏈接
- 20. WordPress的奇怪的永久鏈接
- 21. 我如何重定向所有WordPress的帖子到自定義永久鏈接
- 22. 自定義帖子類型和自定義分類的WordPress永久鏈接
- 23. 如何獲得所有網址參數WordPress的帖子永久鏈接?
- 24. WordPress:需要更改RSS源中的帖子永久鏈接網址
- 25. 如何獲得WordPress多站點共享帖子的永久鏈接
- 26. 的WordPress 3.4.2帖子,檔案和分類定製永久鏈接僅
- 27. WordPress的永久鏈接產品
- 28. WordPress的永久鏈接和重定向
- 29. WordPress的永久鏈接postname 404 on localhost
- 30. WordPress的永久鏈接,以允許在
感謝您的信息:) –