作者:小佛瞌睡蓝 | 来源:互联网 | 2022-12-21 14:47
Update:Iveansweredthismyself.Seebelow.更新:我自己也回答了这个问题。见下文。IguessImaskingfortheequiva
Update: I've answered this myself. See below.
更新:我自己也回答了这个问题。见下文。
I guess I'm asking for the equivalent of a set_the_id()
function, if one existed.
我想我要求相当于set_the_id()函数,如果存在的话。
I'm using Wordpress with Varnish for performance, and I want to use an ESI (Edge Side Include) for the sidebar, so things like recent/popular posts can be refreshed more frequently than the post content itself.
我正在使用Wordpress和Varnish来提高性能,我想在侧边栏中使用ESI(Edge Side Include),因此最近/热门帖子之类的内容可以比帖子内容本身更频繁地刷新。
One way of doing this is creating an endpoint in your plugins directory etc. for Varnish to access from an ESI comment, with some code like this:
一种方法是在插件目录等中创建一个端点,以便Varnish从ESI注释中访问,其代码如下:
All fine so far; this is enough to load Wordpress and it to find all the relevant plugins. However they produce errors at various points (specifically wp-includes/post-template.php
line 29) because they need to use things like get_the_id(), in_category() and properties of the post object to highlight certain posts and so on and no post has been loaded yet.
到目前为止一切都很好这足以加载Wordpress并找到所有相关的插件。但是它们会在各个点(特别是wp-includes / post-template.php第29行)产生错误,因为它们需要使用get_the_id(),in_category()和post对象的属性来突出显示某些帖子等等。帖子已经加载了。
How can I tell Wordpress to load a specific post ID in the code above, as if I'd gone to a URL like http://example.com?p=1
, but without outputting a full page? I just want the environment to be setup as if post was active, then I can pass the current post ID as a parameter in my ESI call.
如何告诉Wordpress在上面的代码中加载特定的帖子ID,好像我去了http://example.com?p=1这样的网址,但没有输出整页?我只是希望设置环境就好像post是活动的,然后我可以将当前的帖子ID作为参数传递给我的ESI调用。
I thought query_posts() might help and I tried adding:
我认为query_posts()可能会有所帮助,我尝试添加:
query_posts( 'p=5' );
but it doesn't do anything.
但它没有做任何事情。
I also wondered about WP_Post::get_instance()
(it only seems to take an object though, not a post ID).
我也想知道WP_Post :: get_instance()(它似乎只是一个对象,而不是一个帖子ID)。
Is there anything else I can use?
还有什么我可以使用的吗?
1 个解决方案