Wordpress中的AJAX导航-固定链接有问题 [英] AJAX navigation in Wordpress - Trouble with Permalinks

查看:73
本文介绍了Wordpress中的AJAX导航-固定链接有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在这里:

我编写了一个博客主题,该主题类似于一个桌子,上面有很多东西,可由用户拖动,移动元素等.博客的主要部分放在一本书中,您可以使用分页标记以及翻页来浏览类别.

I programmed a blogtheme which resembles a desk with lots of stuff on it, draggable by the user, moving elements and so on. The main part of the blog is placed within a book which categories you can browse by using pagemarkers as well as turning pages.

要给用户留下他/她实际上正在使用书"的印象,我首先使用了复杂的结构(主要关注页面标记的位置):

To give the user the impression he/she is actually using a "book" I used a complex structure in first place (concerns mostly the place of the pagemarkers):

  1. 每个类别都使用自己的模板(category-4.php,category-5.php等)
  2. single.php导致类别敏感的模板(总共6个类别)

完成后,我发现图形元素引起的流量过多,因为每次单击时都会重新加载它们,并且页面运行速度非常慢.因此,我考虑了一个AJAX解决方案,并最终使用了ezjax-solution(http://www.fluidbyte.net/index.php?view=simple-ajax-content-changer-with-ezjax),该脚本基本上可以在index.php中的某个div内具有特定类的所有href加载.当链接的内容加载到div中时,我将交互背景的代码(和通讯方式)保存在其他模板文件中,并以此方式保存通讯量.

When I finished I found that there was far too much traffic caused by graphical elements as they were reloaded each click and the page was incredibly slow. So I thought about an AJAX solution and finally used the ezjax-solution (http://www.fluidbyte.net/index.php?view=simple-ajax-content-changer-with-ezjax) which is basically a script that let all a hrefs with a certain class load within a certain div in the index.php. As the content of the links is loaded into the div I save the code (and this way the traffic) for the interactive background in the other template files and this way the traffic.

您可以在此处中查看运行页面,并查看导航的工作方式.

You can check out the running page here and see how the navigation works.

基本上,这正是我想要的,但仍然会造成一些麻烦:

Basically that´s exactly what I wanted but it still causes some trouble:

  1. 作为单个帖子的模板文件,类别例如不包含您无法真正使用永久链接的背景.您实际上可以执行此操作,但它看起来像是整个页面的一半(http://www.palimpsest.eu/2011/02/01/differenzierung/).显然,访问者必须对内容具有正常"的看法.

  1. As the template files of single-posts, categories, e.g. does NOT contain the background you can´t really use permalinks to them. You can actually do that but it would look like half the page (http://www.palimpsest.eu/2011/02/01/differenzierung/). It is evidently important that visitors will get a "normal" view onto the content.

由于某些原因,某些需要与帖子ID挂钩的插件(例如Sexybookmarks或Flattr)无法正常工作.我想原因与1.问题有关.

For some reason some plugins that need to hook up with the ID of the post (like Sexybookmarks or Flattr) don´t work. I guess the reason is connected to the 1. problem.

现在这是我的方法,我想问您,您认为哪种方法最好(或者可能给其他解决问题的方法一些启发):

Now here are my approaches and I would like to ask you which one you consider the best to take (or maybe give some inspiration about other ways to resolve the problem):

  1. 使single.php询问您是内联浏览还是来自外部站点,然后进入两个不同的模板(一个简短,一个包含所有图形内容).在这种情况下,我不知道如何使single.php从您要来的地方实现.

  1. Causing the single.php to ask whether you browse inline or come from an external site and then lead into two differen templates (a short one and one with all the graphical content). In this case I don´t know how to make the single.php realize from where you are coming.

我曾考虑过使用AJAXed Wordpress,但不确定是否适合我的需求.我也没有看到太多有关导航模块的文档.

I thought about using AJAXed Wordpress but I am not sure if it will suit my needs. I also don´t see much documentation about the navigation module.

其他任何方法都不会刷新临时Internet文件中已经存在的内容.

Any other way which won´t refresh the content that is already in the temporary internet files.

我非常感谢能提供解决此问题的建议.

I would be really grateful to get suggestions how to cope with this issue.

最诚挚的问候, 拉拉

推荐答案

欢迎使用SO.我不确定我是否了解您到底要做什么,但这是仅在WP中使用AJAX请求内容的常见难题: 您需要链接,单击后照常加载页面.但是,您也想使用相同的链接通过AJAX加载相同的页面,然后又不想加载布局.

Welcome to SO. I'm not sure if I understand what exactly you're trying to do, but here's the usual dilemma with AJAX requests for content only in WP: You want the link, when clicked load a page as usual. But you also want to use the same link to load the same page via AJAX and then you don't want the layout to be loaded as well.

假设这是您问题的核心,这就是我通常的处理方式:

Assuming that this is the core of your problem, here's how I handle this usually:

// functions.php
function is_ajax_request() {
  return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&   
          strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}


// e.g. in index.php or any other template file:
<?php if (!is_ajax_request()) { get_header(); }  ?>

// ... Rest of your template ...

<?php if (!is_ajax_request()) { get_footer(); } ?>

例如,如果通过AJAX请求模板文件,则仅加载内容,否则页面将照常加载.

Like this only the content is loaded if the template file is being requested via AJAX, otherwise the page loads just as usual.

让我知道这是否对您有帮助,或者以其他方式进一步解释您所追求的. 我注意到附近的人回避了太长的问题.所以-越短越好;)

Let me know if this helps you out, or otherwise explain a little further what you're after. And I've noticed that people around here shy away from too long questions. So — the shorter the better ;)

这篇关于Wordpress中的AJAX导航-固定链接有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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