最好的解决办法重定向URL到一个Ajax版本? [英] Best solution to redirect URLs to an Ajax version?

查看:124
本文介绍了最好的解决办法重定向URL到一个Ajax版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了解阿贾克斯永久的字preSS冥王星主题更多问题

所以这是一个完全的Ajax字preSS的主题,出现在谷歌的所有URL都不会从用户版本的网站,但在下的版本。

So it's a fully Ajax Wordpress theme, all URLs appearing in Google are not from the user version website but the 'underneath' version of it.

例: 链接出现在谷歌:www​​.thaiorchid.be/menus/(诡异的黑色页)相比,用户的网页:www.thaiorchid.be/#menu-item-21

Example: Link appearing in Google: www.thaiorchid.be/menus/ (strange black page) Compared to the user webpage: www.thaiorchid.be/#menu-item-21

我在寻找自动重定向所有网页的最佳途径(像一个/菜单一/#菜单项-21)至少有东西presentable,任何想法,这将是最好的解?

I'm searching for the best way to automatically redirect all pages (like the one /menus to the one /#menu-item-21) to at least have something presentable, any idea what would be the best solution?

推荐答案

不幸的是,我目前无法测试以下,但我相信,这样的事情应该工作,因为该标准的Word preSS菜单这个主题中使用。

Unfortunately I'm currently not able to test the following, but I believe that something like this should work, given that the standard Wordpress menu is used within this theme.

// 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正确的菜单ID,然后重定向使用Javascript如果当前页面不被通过AJAX加载。

This will determine the correct menu ID based on the current post’s or page’s ID and then redirect using Javascript if the current page as not been loaded via AJAX.

同样,我现在还不能测试这一权利可言,但也许它可以帮助你去。

Again, I can’t test this right now at all, but maybe it can help you to go on.

这篇关于最好的解决办法重定向URL到一个Ajax版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆