ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem with including post title in meta title

July 28, 2010 4:32pm

Subscribe [6]
  • #1 / Jul 28, 2010 4:32pm

    Stoelting

    99 posts

    This question may be related to a resolved thread.

    As advised in the related thread, I used the following code in the header title tag to include the entry title in the header title.

    <title>{exp:weblog:entries weblog={master_weblog_name} limit="1" 
    disable="categories|custom_fields|member_data|pagination|trackbacks" group_id="10"}
    {title}{/exp:weblog:entries}
    </title>

    This works correctly, EXCEPT if the author has been changed. The entry title is displayed only for entries by currently assigned authors. Titles for entries by previous authors no longer in the active list are not displayed, even though the entries with titles display correctly on the weblog index & archive pages.

    So far, the only workaround I’ve found is to manually set up the Publish page to display the author menu and set up the user to be included in the author menu, then edit every entry to change to the current author using the author dropdown menu.

    Is there a more efficient work around? Is this problem fixed in EE 2.0? The budget is tight right now, but if I could be certain the problem would be resolved without this workaround by upgrading, it would be worth it to save a lot of time.

  • #2 / Jul 28, 2010 5:40pm

    Ingmar

    29245 posts

    Can you show us a little more of your code? Try to simplify the weblog:entries tag, then add to it until it breaks.

  • #3 / Jul 28, 2010 11:05pm

    Stoelting

    99 posts

    Can you show us a little more of your code? Try to simplify the weblog:entries tag, then add to it until it breaks.

    This is as basic as I can get:

    <title>{exp:weblog:entries weblog={master_weblog_name} limit="1" group_id="20"}{title}{/exp:weblog:entries}
    </title>

    If I don’t include the group ID, it displays the title of the most recent entry across ALL weblogs (could be from any of 25+ weblogs), which could be completely unrelated. This is a very simple weblog. The Publish page has only 2 entry fields: Title, and a custom textarea field. If I limit it to the group ID of the current weblog, the title does not display if the current author is different from the author of the entry who is no longer assigned to the member group, or if there is no member group assigned to the weblog.

    I don’t know if this relates, but all of the changed authors were reassigned to another member group used by a hidden forum. I was unable to have these members assigned to both a weblog group and the hidden forum group. Their functionality in the hidden forum was adversely affected.

  • #4 / Jul 29, 2010 2:01am

    John Henry Donovan

    12339 posts

    Stoelting,

    Why would you need to use the group_id parameter at all. Just use the url_title and put in a segment variable. The number of the segment depends on what your URL looks like.

    <title>
    {exp:weblog:entries weblog={master_weblog_name} limit="1"
     disable="categories|custom_fields|member_data|pagination|trackbacks" url_title="{segment_3}"}
    {title}
    {/exp:weblog:entries}
    </title>
  • #5 / Jul 29, 2010 11:03am

    Stoelting

    99 posts

    I was unaware of the segment variable and how to use it. Thank you.

    This code worked for each individual entry, as you said:

    <title>{exp:weblog:entries weblog="{master_weblog_name}" 
    disable="categories|custom_fields|member_data|pagination|trackbacks" 
    url_title="{segment_2}"}{title}{/exp:weblog:entries}</title>

    However, on the main index page, the title was left blank. So I tried this:

    <title>{exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info} — 
    {exp:weblog:entries weblog="{master_weblog_name}" 
    disable="categories|custom_fields|member_data|pagination|trackbacks" 
    url_title="{segment_2}"}{title}{/exp:weblog:entries}</title>

    For the main index page, the title is then displayed as “(blog title) —” and the individual entry titles are displayed as “(blog title) — (entry title)”.

    I can live with this, but to tweak it a little more, is there a way of writing a conditional that if segment 2 is blank (i.e. for the main index page) it returns the blog title, if not blank it returns “(blog title) — (entry title)”? That would be sweet!

  • #6 / Jul 29, 2010 8:44pm

    Brandon Jones

    5500 posts

    Yes, you can use segment variables with conditionals.

    {if segment_2 == ''}
       {exp:weblog:entries ...}
           ... show only blog title
       {/exp:weblog:entries}
    {if:else}
       {exp:weblog:entries ...}
           ... show blog title and entry title 
       {/exp:weblog:entries}
    {/if}

    Note that exp:weblog:entries (start and end tags) must be fully contained within each {if} branch. Hope that helps!

  • #7 / Jul 31, 2010 3:24pm

    Stoelting

    99 posts

    I’ve tried this:

    {if segment_2 == ""}
    {exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info}
    {if:else}
    {exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info} — 
    {exp:weblog:entries weblog="{master_weblog_name}" 
    disable="categories|custom_fields|member_data|pagination|trackbacks" url_title="{segment_2}"}{title}
    {/exp:weblog:entries}
    {/if}

    But it only returns the content between if:else and /if. The content between if segment… and if:else is ignored when I am on the index page with multiple entries displayed.

  • #8 / Aug 01, 2010 3:36pm

    Greg Salt

    3988 posts

    Hi Stoelting,

    Don’t forget that your segments start from 1 and not 2. So, if you are on your site homepage like this http://www.domain.com then you would need to test for segment_1 being empty and not segment_2.

    Cheers

    Greg

  • #9 / Aug 02, 2010 9:51am

    Stoelting

    99 posts

    Hi Stoelting,

    Don’t forget that your segments start from 1 and not 2. So, if you are on your site homepage like this http://www.domain.com then you would need to test for segment_1 being empty and not segment_2.

    My EE site is in a subdirectory of my domain so the index page that I’m testing is:

    <a href="http://mydomain.com/eedirectory/index.php?/weblog1/index/">http://mydomain.com/eedirectory/index.php?/weblog1/index/</a>

    Would “index” be segment_1 or segment_2?

    The url for the individual entry page is

    <a href="http://mydomain.com/eedirectory/index.php?/weblog1/url_title/">http://mydomain.com/eedirectory/index.php?/weblog1/url_title/</a>

    Using segment_2 here returns the correct entry title.

  • #10 / Aug 02, 2010 12:39pm

    Sue Crocker

    26054 posts

    weblog1 is segment_1, index in the first case would be segment_2

    The url_title in this case is segment_2.

    Normally my links look like this:

    http://example.com/index.php/template_group/template_name/url_title for single entry pages.

    Does that help?

  • #11 / Aug 02, 2010 2:35pm

    Stoelting

    99 posts

    weblog1 is segment_1, index in the first case would be segment_2

    The url_title in this case is segment_2.

    Normally my links look like this:

    http://example.com/index.php/template_group/template_name/url_title for single entry pages.

    Does that help?

    This confirms what I thought: segment_2 would apply to both “index” and “url_title” for these links.

    I have observed that with this code:

    <title>{exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info} — 
    {exp:weblog:entries weblog="{master_weblog_name}" url_title="{segment_2}"}{title}{/exp:weblog:entries}</title>

    I get “blog_title —” for the index page and “blog_title — url_title” for the entry page. That seems to imply segment_2 is blank for the index page.

    If this is true then it seems that the conditional code:

    {if segment_2 == ""}
    Blank
    {if:else}
    Else
    {/if}

    should return “Blank” for the index page and “Else” for the url_title page. But it actually returns “Else” for both pages. I assume that there should be no space between the “” in the “if” code above.

    Maybe I’m asking for the moon here. I was just hoping there was a way for the index page to show only “blog_title” (without the emdash) and the url_title page to show “blog_title — url_title”. If that’s asking too much, I can live with the index title ending with the dash.

  • #12 / Aug 02, 2010 7:19pm

    Brandon Jones

    5500 posts

    Stoelting, EE will default to the index template if no template is specified in segment_2. So instead of

    http://mydomain.com/eedirectory/index.php?/weblog1/index/ 

    You should be able to use

    http://mydomain.com/eedirectory/index.php?/weblog1/

    Make sense?

  • #13 / Aug 03, 2010 11:55am

    Stoelting

    99 posts

    That was the missing piece. It works exactly as I wanted it to. Thanks to all the contributors to this thread. It has been a great education that I can apply to many areas. No further questions. 😊

  • #14 / Aug 03, 2010 12:49pm

    Ingmar

    29245 posts

    Glad to see you’re all set. Please post again in case there’s anything else.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases