如何在 ExpressionEngine 2 的浏览器标题栏中自动显示条目/文章的标题?
如何在 ExpressionEngine 中输出条目的标题并将其显示在浏览器的标题栏中?
这是我的页面标题的内容:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Site</title>
<link rel="stylesheet" href="{stylesheet=site/site_css}" type="text/css" media="screen" />
</head>
我需要的是每个页面都在浏览器的标题栏中显示条目的标题 - 我怎样才能实现这一点?
更新代码的一部分:
这是我的做法:
{exp:channel:entries channel="news_articles" status="open|Featured Top Story|Top Story" limit="1" disable="member_data|trackbacks|pagination"}
{embed="includes/document_header" page_title=" | {title}"}
<body class="home">
<div id="layoutWrapper">
{embed="includes/masthead_navigation"}
<div id="content">
<div id="article">
<img src="{article_image}" alt="News Article Image" />
<h4>{title}</h4>
<h5><span class="by">By</span> {article_author}</h5>
<p>{entry_date format="%M %d, %Y"} -- Updated {gmt_edit_date format="%M %d, %Y"}</p>
{article_body}
{/exp:channel:entries}
</div>
你觉得怎么样?
How would I output the title of an entry in ExpressionEngine and display it in the browser's title bar?
Here is the content of my page's header:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Site</title>
<link rel="stylesheet" href="{stylesheet=site/site_css}" type="text/css" media="screen" />
</head>
What I need is for each page to display the title of the entry in my browser's title bar — how can I achieve that?
Part of UPDATED Code:
Here is how i have done it :
{exp:channel:entries channel="news_articles" status="open|Featured Top Story|Top Story" limit="1" disable="member_data|trackbacks|pagination"}
{embed="includes/document_header" page_title=" | {title}"}
<body class="home">
<div id="layoutWrapper">
{embed="includes/masthead_navigation"}
<div id="content">
<div id="article">
<img src="{article_image}" alt="News Article Image" />
<h4>{title}</h4>
<h5><span class="by">By</span> {article_author}</h5>
<p>{entry_date format="%M %d, %Y"} -- Updated {gmt_edit_date format="%M %d, %Y"}</p>
{article_body}
{/exp:channel:entries}
</div>
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一种相对较新的解决方法是使用 Stash 插件和模板部分方法。这种方法可以让您只剩下一个嵌入,并且具有额外的优点,即为您提供一个集中的“包装”模板 - 基本上每个主要页面布局都有一个模板。下面的示例假设您只是添加了自定义字段来处理您想要注入标头的任何特定于条目的元数据。考虑到这个想法,这是我最近应用的基本结构的简化视图:
在模板中应用 EE 标签来确定发送到内部包装器的逻辑
然后在您的包装模板中,该模板最终将包含所有包装 HTML,但可以分为片段。对于诸如标头之类的内容,因为它将与其他包装模板共享,例如:
Another relatively new way to tackle it is using the Stash add-on and a template partials approach. This method knocks you down to one embed, and has the added advantage of giving you a centralized "wrapper" template - one for each major page layout, basically. The example below assumes you've simply added custom fields to handle any entry-specific meta data you're looking to inject into the header. With this idea in mind, here's a simplified view of the basic structure I've been applying recently:
In your template you apply EE tags to determine the logic of what gets sent to the inside-wrapper
And then in your wrapper template, which would ultimately contain all your wrapping HTML but could be chunked into snippets. for something like the header since it would be shared with other wrapper templates, for example:
如果您只想显示 ExpressionEngine 站点的名称(如 CP Home > Admin > General Configuration 中定义),请使用 站点名称全局变量:
如果要显示仅来自给定频道的当前条目标题使用以下内容:
许多 Web 开发人员将使用 嵌入变量嵌入模板将“{entry_title}”传递到全局嵌入模板,从而允许动态页面标题:
如果您使用 EE2,则 SEO Lite 模块 只需一行代码即可为您处理所有艰苦的工作:
其他解决方案包括 低标题插件 (EE1,EE2)。
If you want to show just the name of your ExpressionEngine site (as defined in CP Home > Admin > General Configuration) use the site name global variable:
<title>{site_name}</title>
If you want to display just the current entry title from a given channel use the following:
Many Web Developers will use an Embed Variable with an Embedded Template to pass the `{entry_title} to a global embed template, allowing for a dynamic page title:
If you're using EE2, the SEO Lite Module takes care of all the hard work for you with a single line of code:
Other solutions include the Low Title Plugin (EE1, EE2).
Ryan 嵌入方法的一项补充(这绝对是最灵活的方法):您可以在查看单个条目时将页面的大部分内容包装在
{exp:channel:entries}
标记中,从而避免额外的(且昂贵的)通道:条目调用。所以它看起来更像是这样的:One addition to Ryan's embed method (which is definitely the most flexile method): chances are you can wrap most of your page in an
{exp:channel:entries}
tag when viewing an individual entry, avoiding the additional (and expensive) channel:entries call. So it would look more like this:NSM Better Meta 是将通道元数据传递到标签的更完整的方法。
对于较小的网站,我使用String插件。
https://devot-ee.com/add-ons/string
语法非常简单。
NSM Better Meta is a more complete way to pass channel meta data to the tag.
For smaller sites, I use the String plugin.
https://devot-ee.com/add-ons/string
Very simple syntax.