Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
993 views
in Q2A Core by

In my website, question page TITLE shows -

<title> = Question in one sentence + Index page title

 

I want to shows like this -

<title> = Question in one sentence (upto 68 character)

 

Is it possible?

2 Answers

0 votes
by
edited by

Not sure why you need to restrict it to 68 characters. If you're worried about SEO or something, it doesn't matter.

First create an advanced theme as described here. Then you can override the head_title function with something like this:

function head_title()
{
    if ($this->request == 'question')
    {
        $this->content['title'] = qa_shorten_string_line($this->content['title'], 68);
    }
    parent::head_title();
}

It checks if you're on a question page and if so, truncates the string at 68 characters. The last line calls the base function (so it will survive future upgrades).

by
The answer is right but that should be 'question' not 'questions', to identify a question page. Also qa_shorten_string_line(...) in qa-util-string.php will shorten a string for you without chopping words in the middle - might be helpful.
by
okey.

then i rather change only page title.

Page Title = $pagetitle >>>>> not page title + site title

I tried,


        function head_title()
        {
            $pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
            $headtitle=(strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title'];
           
            $this->output('<TITLE>'.$pagetitle.'</TITLE>');



But it removes my site title.

Any suggestion?
by
why would you use strlen($this->request) ? that doesn't perform any useful function.  What you need is what Scott says, if ($this->request == XXX).
0 votes
by
edited by
Maybe something like this is what you need:

<?php

    class qa_html_theme extends qa_html_theme_base
    {
        function head_title()
        {
            if($this->template == 'question') {
                $pagetitle=strip_tags(@$this->content['title']);
                $this->output('<TITLE>'.$pagetitle.'</TITLE>');
            }
            else qa_html_theme_base::head_title();
        }
    }
by
edited by
No changes in meta head of question page.

Here is my qa-theme.php

<?php

    class qa_html_theme extends qa_html_theme_base
    {
    function head_title()
      {
    if($this->request == 'question') {
    $pagetitle=strip_tags(@$this->content['title']);
    $this->output('<TITLE>'.$pagetitle.'</TITLE>');
    }
    else qa_html_theme_base::head_title();
    }
    }
/*
    Omit PHP closing tag to help avoid accidental output
*/
by
Ah, sorry, you all got me confused... it's $this->template, not $this->request

<?php

    class qa_html_theme extends qa_html_theme_base
    {
        function head_title()
        {
            if($this->template == 'question') {
                $pagetitle=strip_tags(@$this->content['title']);
                $this->output('<TITLE>'.$pagetitle.'</TITLE>');
            }
            else qa_html_theme_base::head_title();
        }
    }
by
working perfectly. Thanks.
...