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

Ibn*_*eed 3 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>
Run Code Online (Sandbox Code Playgroud)

我需要的是每个页面在我的浏览器标题栏中显示条目的标题 - 我该如何实现?


更新代码的一部分:

我是这样做的:

{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>
Run Code Online (Sandbox Code Playgroud)

你怎么看?

Jea*_*and 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}
Run Code Online (Sandbox Code Playgroud)

然后在你的包装器模板中,它最终将包含你所有的包装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>
Run Code Online (Sandbox Code Playgroud)


rjb*_*rjb 6

如果只想显示ExpressionEngine站点的名称(如CP Home> Admin> General Configuration中所定义),请使用站点名称全局变量:

<title>{site_name}</title>

如果要仅显示给定通道的当前条目标题,请使用以下命令:

<title>
    {exp:channel:entries channel="channel_name" limit="1" dynamic="yes"}
        {title}
    {/exp:weblog:entries}
</title>
Run Code Online (Sandbox Code Playgroud)

许多Web开发人员将使用嵌入式模板嵌入变量将`{entry_title}传递给全局嵌入模板,从而允许动态页面标题:

{embed="includes/header" title="{exp:channel:entries channel="{channel_name}"}{title}{/exp:channel:entries}"}
Run Code Online (Sandbox Code Playgroud)

如果您正在使用EE2,SEO Lite模块将通过一行代码为您完成所有艰苦的工作:

<html lang="en">
<head>
    <meta charset="utf-8" />
    {exp:seo_lite url_title="{url_title}"}
</head>
Run Code Online (Sandbox Code Playgroud)

其他解决方案包括低标题插件 (EE1,EE2).