Wordpress 中的 AJAX 导航 - 固定链接问题

发布于 2024-10-15 11:14:18 字数 1269 浏览 0 评论 0原文

这就是我的位置:

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

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

  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 内具有特定类加载的所有 a href。当链接的内容加载到 div 中时,我将交互背景的代码(这样的流量)保存在其他模板文件中,这样的流量。

您可以在此处查看运行页面并了解导航的工作原理。

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

  1. 作为单个帖子、类别的模板文件,例如不包含背景,您不能真正使用它们的永久链接。你实际上可以这样做,但它看起来就像半个页面(http://www.palimpsest.eu/2011/02/01/differenzierung/)。显然,访问者获得内容的“正常”视图非常重要。

  2. 出于某种原因,一些需要与帖子 ID 连接的插件(如 sexybookmarks 或 Flattr)无法工作。我猜原因与 1. 问题有关。

现在这里是我的方法,我想问您认为最好采用哪一种(或者可能提供一些有关解决问题的其他方法的灵感):

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

  2. 我考虑过使用 AJAXed Wordpress,但我不确定它是否能满足我的需求。我也没有看到太多有关导航模块的文档。

  3. 任何其他不会刷新 Internet 临时文件中已有内容的方式。

我将非常感激获得如何处理这个问题的建议。

此致, 劳拉

So here´s where I am:

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. Every category uses its own template (category-4.php, category-5.php, etc.)
  2. The single.php leads to category-sensitive templates (6 categories alltogether)

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. 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.

  2. 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. 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.

  2. 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.

  3. 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.

Best regards,
Lara

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尹雨沫 2024-10-22 11:14:18

欢迎来到SO。我不确定我是否理解您到底想要做什么,但这是仅在 WP 中请求内容的 AJAX 常见的困境:
您需要链接,当单击时像往常一样加载页面。但您还想使用相同的链接通过 AJAX 加载相同的页面,然后您不希望也加载布局。

假设这是您问题的核心,以下是我通常处理此问题的方法:

// 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 请求模板文件,则仅加载内容,否则页面将像往常一样加载。

让我知道这是否对您有帮助,或者进一步解释一下您的需求。
我注意到这里的人们回避太长的问题。所以——越短越好;)

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(); } ?>

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 ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文