如何在ExpressionEngine 2的浏览器标题栏中自动显示条目/文章的标题?

时间:2011-05-31 16:00:52

标签: expressionengine

如何在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>

您怎么看?

4 个答案:

答案 0 :(得分:8)

解决这个问题的另一种相对较新的方法是使用Stash附加组件和模板部分方法。这种方法将你击倒到一个嵌入,并且具有额外的优势,即为您提供集中的“包装”模板 - 基本上每个主要页面布局一个。下面的示例假设您只是添加了自定义字段来处理您希望注入标头的任何特定于条目的元数据。考虑到这个想法,这里是我最近应用的基本结构的简化视图:

在您的模板中,您应用EE标记来确定发送到内包装的内容的逻辑

{embed="embeds/.inside-wrapper"}

{exp:channel:entries channel="channel_name" limit="1" dynamic="yes" disable="whatever|you|can|live|without"}

{!-- ENTRY SEO META DATA --}
{exp:stash:set name="entry_seo_title" scope="site"}{cf_channelprefix_seo_title}{/exp:stash:set}
{exp:stash:set name="entry_seo_description" scope="site"}{cf_channelprefix_seo_description}{/exp:stash:set}
{exp:stash:set name="entry_seo_keywords" scope="site"}{cf_channelprefix_seo_keywords}{/exp:stash:set}

{!-- ENTRY/PAGE CONTENT --}
{exp:stash:set name="entry_body_content" parse_tags="yes" parse_conditionals="yes" scope="site"}
Your page content here
{/exp:stash:set}

{/exp:channel:entries}

然后在你的包装器模板中,它最终会包含你所有的包装HTML,但可以分成几个片段。因为它将与其他包装模板共享,例如:

<html>
<head>
<title>{exp:stash:get name="entry_seo_title"}</title>
<meta name="description" content="{exp:stash:get name="entry_seo_description"}" />
<meta name="keywords" content="{exp:stash:get name="entry_seo_keywords"}" />
</head>

<body>

{exp:stash:get name="entry_body_content"}

</body>
</html>

答案 1 :(得分:6)

如果您只想显示ExpressionEngine网站的名称(如CP Home&gt; Admin&gt; General Configuration中所定义),请使用site name global variable

<title>{site_name}</title>

如果您只想显示给定频道的当前参赛作品标题,请使用以下内容:

<title>
    {exp:channel:entries channel="channel_name" limit="1" dynamic="yes"}
        {title}
    {/exp:weblog:entries}
</title>

许多网络开发人员将使用Embed Variable with an Embedded Template将`{entry_title}传递给全局嵌入模板,允许dynamic page title

{embed="includes/header" title="{exp:channel:entries channel="{channel_name}"}{title}{/exp:channel:entries}"}

如果您正在使用EE2,SEO Lite Module只需一行代码即可为您完成所有艰苦工作:

<html lang="en">
<head>
    <meta charset="utf-8" />
    {exp:seo_lite url_title="{url_title}"}
</head>

其他解决方案包括Low Title Plugin (EE1,EE2)

答案 2 :(得分:2)

Ryan嵌入方法的一个补充(绝对是最灵活的方法):在查看单个条目时,您可以将大部分页面包装在{exp:channel:entries}标记中,从而避免额外(且昂贵)的频道:条目呼叫。所以它看起来更像是这样:

{exp:channel:entries channel="channel_name" limit="1"}
    {embed="includes/header" title="{title}"}
    <h1>{title}</h1>
    {page_content}
    {embed="includes/footer"}
    {if no_results}{redirect="404"}{/if}
{/exp:channel:entries}

答案 3 :(得分:2)

NSM Better Meta是一种将渠道元数据传递给代码的更完整方式。

对于较小的网站,我使用字符串插件。

https://devot-ee.com/add-ons/string

非常简单的语法。

相关问题