谷歌上的所有URL不是来自用户版本网站, 而是下面的版本。
Example: Link appearing in Google: www.thaiorchid.be/menus/ (strange black page) Compared to the user webpage: www.thaiorchid.be/#menu-item-21
我正寻找最佳方法, 自动重定向所有页面(如单页/菜单到单页/#菜单-项目21), 至少要有现成的东西,
谷歌上的所有URL不是来自用户版本网站, 而是下面的版本。
Example: Link appearing in Google: www.thaiorchid.be/menus/ (strange black page) Compared to the user webpage: www.thaiorchid.be/#menu-item-21
我正寻找最佳方法, 自动重定向所有页面(如单页/菜单到单页/#菜单-项目21), 至少要有现成的东西,
不幸的是,我目前无法测试以下内容,但我认为,鉴于标准Wordpress菜单用于这一主题,类似的东西应该有效。
// functions.php
function get_menu_id_for_post($post_id) {
global $wpdb;
$query = $wpdb->prepare(
"
SELECT post_id
FROM $wpdb->postmeta
WHERE meta_key = _menu_item_object_id
AND meta_value = %s
",
$post_id
);
$menu_id = $wpdb->get_var($query);
return $menu_id;
}
function is_ajax_request() {
return (!empty($_SERVER[ HTTP_X_REQUESTED_WITH ]) &&
strtolower($_SERVER[ HTTP_X_REQUESTED_WITH ]) == xmlhttprequest );
}
// partial template, right on the top:
<?php if (!is_ajax_request()): ?>
<script type="text/javascript">
window.location = "http://www.thaiorchid.be/#menu-item-<?php echo get_menu_id_for_post($post->ID) ?>";
</script>
<?php endif; ?>
这将根据当前日志或页面的 ID 来确定正确的菜单代号, 如果当前页面未通过 AJAX 装入, 则使用 Javascript 重新定位 。
但或许这能帮助你继续前进。
后向兼容性以正确的方式写下链接, 但添加一个关系/类, 你总是觉得舒服的 :
<a href="http://example.com/path/to/file.html" rel="ajax" >link</a>
然后从里说:
$( a[rel=ajax] ).click(function(e) {
//do whatever
e.preventDefault();
});
某些情况下, 我跳过添加“ 强” >rel = "ajax" 强” 或“强” 类 = “ajax” 强”, 只是寻找连接到网站域的链接 :
$( a[href^="http://example.com"] ).click(function(e) {
//do whatever
e.preventDefault();
});
通常我的“ 坚固” 方法使 ajax 得到与初始链接中相同的附加。 它只是添加了一个参数 < enger >? ajaax=1 , 这样模板就可以跳过页眉/脚的输出( 当我使用 AHAH) 或 Json_en 编码响应( JSON 输出) 。
I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...
I m trying to find a reusable way to set focus from one text box to another upon enter using ASP.NET, but using client-side JavaScript to do so. The only reason I mention this is to be done in ASP....
I have some Javascript JQuery code that does an Ajax call to the server every 5 mins, it s to keep the server session alive and keep the user logged in. I m using $.ajax() method in JQuery. This ...
Why are my AJAX requests failing? I have a website www.foo.com, and I m running Tomcat on the same server, www.foo.com:8080/services. However, when a file on foo.com makes an ajax call as such: $....
I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...
I have a entry form. Below it, I want to show a grid containing existing records. As the user clicks on a row of the grid, the values must get filled in the fields of the form above. Is there any way ...
I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...
Ok, I m stumped. Basically, this script works fine in FF, but not in IE (6,7 or 8) - in which it returns an "Object doesn t support this property or method" error. Any ideas?: function ...