Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

pagination and meta titles

edited February 2008 in Vanilla 1.0 Help
Hi all, I need to be able to show the page number in the (meta) title of the page. Does anyone know how to do this please? Many thanks :)
«1

Comments

  • Options
    One way to get the current page number is by using ForceIncomingInt:$Page = ForceIncomingInt('page', 1);
    I realized this isn't truly proper, as there is one case (coming from a search result) where you can be on a secondary page without the page querystring appearing in the URL.

    So understanding that, this will work for the other 95% of the time when the page is defined in the URL:$Page = ForceIncomingInt('page', 1); // Figure out what page we are on $Headlinks = '<link rel="first" href="[first url]"/>'; // First page in the sequence if ($Page > 1) { $Headlinks .= '<link rel="previous" href="[previous url]"/>'; } $Head->AddString($Headlinks);
    The code is from a old extension idea of mine to add link headers to support link bars in browsers. Many more link types to add than what I have here.
  • Options
    Thanks a lot Wallphone. I will try this out tonight. in theory, a search result will not produce a spiderable url anyway, and it is search engines this is for, not users so much. BTW - can this be used on both discussions.php (i assume) and also the case where you go to a paginated page within a category itself? If so, what file would this be applied to then? eg http://www.widget.com/widget-forum/3/2/ Many Cheers.
  • Options
    You could do this in the root files, but a better solution would be to wrap it with the extension code, then you can switch it on and off at will in the control panel, and when you update Vanilla you won't have to re-do your changes every time.

    That example is probably a bit simplistic, so here are some more extension examples. The $Head object, while different, works similarly enogh as the $Panel object for you to do what you want.
  • Options
    Hi Wallphone, Sorry, I am a bit lost. Where would i put this code please?
  • Options
    halo_12: in theory, a search result will not produce a spiderable url anyway, and it is search engines this is for, not users so much

    Funny you should say that, I recently set up a Google custom search gadget and while testing it, I found the Google search results included results from a Vanilla search. Very odd, are Vanilla searches saved somewhere in a cache that Google is able to scan?
  • Options
    Halo: You would have to put it in a folder inside the extensions folder, with the extension comments named default.php.

    Then turn it on just like any other extension.

    Wanderer: Google's bot doesn't itself perform serches, but if someone else did a search, and posted the search URL somewhere Google would see it, then it would appear in Google's search results. You could probably add a noindex meta tag on the search pages if you didn't want this to happen.
  • Options
    Sorry guys, this is beyond me. Tried adding it to comments.php and broke the page. Can anyone either explain it a bt simpler, or provide the wrapped code for use as an extension? Sorry to be a pain :(
  • Options
    1. Create a folder called MetaPage.
    2. Save this code into that folder in a file named default.php. (you may have to changes some of the code to suit your needs--just ask if you get lost)
    3. Upload this folder to your vanilla's extensions folder
    4. Sign-in as administrator, go to your settings tab, then manage extensions, and check its box.
    5. Profit!!!
    <?php /* Extension Name: Meta Page Number Extension Url: The url to where this extension can be downloaded Description: Adds a meta tag with the page number Version: beta Author: Your Name Author Url: Your personal url */ $Page = ForceIncomingInt('page', 1); // Figure out what page we are on // First page in the sequence $Headlinks = '<link rel="first" href="[first url]"/>'; // This block of code only runs if the page number is greater than one if ($Page > 1) { $Headlinks .= '<link rel="previous" href="[previous url]"/>'; } $Head->AddString($Headlinks); $Head->AddString('<meta name="PageNumber" value="' . $Page . '">"'); ?>
  • Options
    many thanks wall phone
  • Options
    edited October 2007
    killed my forum :( Fatal error: Call to a member function on a non-object in /path-to-my-forum/index.php on line 79 Line 79: $Page->AddRenderControl($Head, $Configuration['CONTROL_POSITION_HEAD']); any thoughts?
  • Options
    Ooh, that is bad... To get your forum back up if you haven't already, go into conf/extension.php and take out the line for that extension--it'll probably be at the bottom.

    I will look into the error, when I get home but am not quite sure what it could be at this point.
  • Options
    Yeah, I got the forum back up no prob. Pagination in meta title would be a great stock standard mod I think.
  • Options
    edited October 2007
    You can't use the variable $Page for that.
    $Page = ForceIncomingInt('page', 1); // Figure out what page we are on

    Replace $Page by $CurrentPage in default.php.
  • Options
    edited October 2007
    Well, I tried replacing that, which leaves me with the following: <?php /* Extension Name: Meta Page Number Extension Url: The url to where this extension can be downloaded Description: Adds a meta tag with the page number Version: beta Author: Your Name Author Url: Your personal url */ $CurrentPage = ForceIncomingInt('page', 1); // Figure out what page we are on // First page in the sequence $Headlinks = '<link rel="first" href="[first url]"/>'; // This block of code only runs if the page number is greater than one if ($CurrentPage > 1) { $Headlinks .= '<link rel="previous" href="[previous url]"/>'; } $Head->AddString($Headlinks); $Head->AddString('<meta name="PageNumber" value="' . $CurrentPage . '">"'); ?> This time it didnt break, but at the same time it didn't do anythign at all! Nothng added to the meta title.:(
  • Options
    It works for me--it probably will be the last bit of code before the </head>. Appears I accidentally put some extra quotes in there also, so '">"'); at the end should actually be '">');
  • Options
    edited October 2007
    For the meta tag you can use Head::Meta like $Head->Meta['PageNumber'] = $CurrentPage;

    When you talk about the meta title, are you talking about the title tag?
  • Options
    Hi Dinoboff, yes I am. So if the page is on page 2, then i want the title to be "My Forum Page 2" as the title (and for that matter the H1 tag on the page oo if possible. This would apply to both discussions and categories - any page that is paginated. If I use: $Head->Meta['PageNumber'] = $CurrentPage; How do I add that? Do I add it in here somehow: <title>'.$this->Context->PageTitle.'</title> ?
  • Options
    edited October 2007
    Can anyone shed light on this for me? I really thought people would have wanted to use this kind of thing for sure :( Any chance of it being included in a new release of vanilla perhaps? Many thanks :)
  • Options
    edited October 2007
    I played around with this idea before via an extension as described and did get it to work. I just added this currentpage and links idea and that worked too. I also have this working with the DiscussionTags add-on to pull the tags and put them in the meta keywords on the comments page. Let me know if I can help.

    I've also been using the MetaTags add-on.

    For example, on my account page I get:
    <head> <title>Mentor Community - My Account</title> <link rel="shortcut icon" href="/Vanilla.1/themes/Digg/styles/Digg-RP/favicon.ico" /> <meta name="Description" content="Profile of My beautiful members" />
    Then after the link and style tags, I get:
    <meta name='keywords' content='contest, Christian, free, contests, winners' /> <meta name='description' content='This forum is great!' /> <link rel="first" href="[first url]"/><meta name="PageNumber" value="1"/></head>
    Bottom line is that I have not gone back to this to get it exactly the way that I would like it.
  • Options
    ok, got it (with some help from a friend). Many thanks for your time everyone :)
This discussion has been closed.