Wordpress - 如何在预期的模板层次结构之外创建自己的模板并向其提供查询?
背景
我使用 WordPress 自定义帖子类型为我的网站创建新闻通讯部分。新闻通讯由文章 (dm_article) 组成,这些文章按问题分类 (dm_issues) 进行分组。
1) 我创建了所有时事通讯文章的索引。我正在使用名为 taxonomy-dm_issues.php 的模板在选定的问题中循环,并显示每篇文章的标题、摘录和完整内容的链接,该链接由 single-dm_article 管理。 PHP。这很好用。
2)我还想为问题创建第二个基于分类的模板。这将充当打印友好选项:“打印整个新闻通讯”。我希望模板能够循环并显示每篇文章的标题、摘录和详细描述。有些外观和感觉也会有所不同。
对于#2,假设我创建了一个名为 print-dm_issues.php 的模板。目前它看起来与taxonomy-dm_issues.php 相同,只是它具有每篇文章的附加长描述数据并包含一些不同的样式。
我想设置这个“打印友好”选项,而不会让 WordPress 管理员在创建问题和文章时必须跳过任何障碍。我也不希望每次创建新问题时都必须创建新模板。
核心问题:
我的要求可以归结为:如何在预期的模板层次结构之外创建自己的 WordPress 模板并向其提供查询?请注意,我使用的是“月份和名称”通用永久链接结构,因此我将不得不破坏我的 htaccess。
替代方案:
1)我的后备方案是让 taxonomy-dm_issues.php 包含两种变体的信息并使用样式来处理不同的视图状态。我知道该怎么做。但是,为了加载时间,我宁愿不这样做。
2) 使用 Ajax 通过单击一次来获取所有文章长描述 (the_content()) 是一个选项,但我不知道如何操作。
3)???
BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
无论是否有干净的 URL,如果您只想返回单个分类术语并根据术语设置不同的页面样式,则可以通过链接查询字符串传递基于分类的变量。
通过将变量传递到查询参数中,在 WordPress 'query_posts' 文档中引用了此内容: http:// /codex.wordpress.org/Function_Reference/query_posts#Example_4
例如,在下面的链接中,标题是根据 URL 中的字符串生成的。
http://lph.biz/areas-we-serve/service- region/?region=Conestoga
您可以设置一个参数,如果在未定义变量的情况下访问页面,该参数将返回默认值。见下文:
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below: