vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Adding <link rel="prev" etc (https://vborg.vbsupport.ru/showthread.php?t=306081)

dethfire 12-19-2013 09:40 PM

Adding <link rel="prev" etc
 
Has anyone been successful in adding <link rel="prev and "next" tags in their threads? I see most current software is doing this regardless of physical pagination.

Ameise 01-06-2015 09:06 PM

I try it with the
Code:

<if condition="$show['next']"><link rel="next" href="$address$address2&amp;page=$nextpage</if>
<if condition="$show['prev']"><link rel="prev" href="$address$address2<if condition="$prevpage != 1">&amp;page=$prevpage</if></if>

but the hook is not active in the headinclude

ozzy47 01-06-2015 09:36 PM

Thanks for posting the suggestion, even though the question was asked thirteen months ago. :p

Ameise 01-07-2015 08:42 AM

But is not solved.
I try something in the function.php by line 2405 to add the headinclude, but it doesnt work.

ozzy47 01-07-2015 09:55 AM

1 Attachment(s)
Just to be clear, you are trying too add something like in the attached screenshot?

kh99 01-07-2015 02:13 PM

Quote:

Originally Posted by Ameise (Post 2530815)
I try it with the
Code:

<if condition="$show['next']"><link rel="next" href="$address$address2&amp;page=$nextpage</if>
<if condition="$show['prev']"><link rel="prev" href="$address$address2<if condition="$prevpage != 1">&amp;page=$prevpage</if></if>

but the hook is not active in the headinclude

Yeah, the problem is that the headinclude template is rendered before any of the page values are calculated. What you might be able to do is a str_replace on the $header variable at some later time. I'd have to know your exact version (and have that source available) to know what's around line 2405 of function.php. But maybe you can use a plugin at hook locaton pagenav_complete to add them, with code something like:
PHP Code:

global $headinclude;
if (
$show['next'])
{
   
$headinclude .= "<link rel=\"next\" href=\"{$address}{$address2}&amp;page={$nextpage}\"/>\n";
}
if (
$show['prev'])
{
   
$headinclude .= "<link rel=\"prev\" href=\"{$address}{$address2}&amp;page={$prevpage}\"/>\n";



Edit: (I replaced the above code - I copied the wrong version).

Ameise 01-15-2015 09:32 AM

Works fine with this code:
Code:

if ($pagenumber > 1)
        {
        global $headinclude;
                $prevpage = $pagenumber - 1;
                $prevnumbers = fetch_start_end_total_array($prevpage, $perpage, $results);
                $show['prev'] = true;
                $headinclude .= "<link rel=\"prev\" href=\"{$address}&amp;page={$prevpage}\">\n";
        }
        if ($pagenumber < $totalpages)
        {
        global $headinclude;
                $nextpage = $pagenumber + 1;
                $nextnumbers = fetch_start_end_total_array($nextpage, $perpage, $results);
                $show['next'] = true;
                $headinclude .= "<link rel=\"next\" href=\"{$address}&amp;page={$nextpage}\">\n";
        }


hilaryl 01-19-2015 01:17 AM

How would you do this without making changes to functions.php?

Is there a way to get the variables you need by using a plugin?

Been stumped on this one for a while.

Cheers,
hilaryl

kodbg 03-12-2015 11:32 AM

So, is there a solution for adding prev / next in head?

PP - Sorry, the code above works fine - thank you

hilaryl 04-01-2015 09:59 PM

Quote:

Originally Posted by Ameise (Post 2532644)
Works fine with this code:
Code:

if ($pagenumber > 1)
        {
        global $headinclude;
                $prevpage = $pagenumber - 1;
                $prevnumbers = fetch_start_end_total_array($prevpage, $perpage, $results);
                $show['prev'] = true;
                $headinclude .= "<link rel=\"prev\" href=\"{$address}&amp;page={$prevpage}\">\n";
        }
        if ($pagenumber < $totalpages)
        {
        global $headinclude;
                $nextpage = $pagenumber + 1;
                $nextnumbers = fetch_start_end_total_array($nextpage, $perpage, $results);
                $show['next'] = true;
                $headinclude .= "<link rel=\"next\" href=\"{$address}&amp;page={$nextpage}\">\n";
        }


Have added this as a plugin - and pushing the links to page so that's bloody awesome.

Have been looking for a solution to this issue for a while now - and this is perfect. Had to tweak a few things to allow for my URL structure - but it's working perfectly now.

Also added in an if statement to cater for being on page 2 and not including a 'page=1' to the previous page.

THANK YOU VERY MUCH!!

darnoldy 04-11-2015 02:07 PM

Quote:

Originally Posted by hilaryl (Post 2542127)
Also added in an if statement to cater for being on page 2 and not including a 'page=1' to the previous page

That's an important addition?could you post your revised code so we can see where you added it, please?

Thanks to everyone who contributed. This is good stuff.

Two questions:

When I create the plugin, what hook do I attach it to?

Do I need to put a variable into the headinclude utilize the results of this code?

SnakeV 06-30-2015 05:37 PM

First i would like to thank you kh99 and Ameise, the code on post #7 works perfectly for SHOWTHREAD and FORUMDISPLAY pages.

The unique problem is with tag pages, on the second page of the tags it adds a rel="prev"

<link rel="prev" href="http://www.vbulletin.com/tags/messenger-page1.html" />

When it should simply be
<link rel="prev" href="http://www.vbulletin.com/tags/messenger.html" />

I'm using vBSEO anyway when i disable it, it also add &page=1.

Any idea how can this be fixed?

Thanks!

kh99 06-30-2015 07:09 PM

Yeah, hilaryl mentioned that he (or she) add a line for that. I guess it would be something like:
PHP Code:

if ($pagenumber 1)
{
   global 
$headinclude;
   
$prevpage $pagenumber 1;
   
$prevnumbers fetch_start_end_total_array($prevpage$perpage$results);
   
$show['prev'] = true;
   if (
$pagenumber == 2)
   {
      
$headinclude .= "<link rel=\"prev\" href=\"{$address}\">\n";
   }
   else
   {
      
$headinclude .= "<link rel=\"prev\" href=\"{$address}&amp;page={$prevpage}\">\n";
   }
}
if (
$pagenumber $totalpages)
{
   global 
$headinclude;
   
$nextpage $pagenumber 1;
   
$nextnumbers fetch_start_end_total_array($nextpage$perpage$results);
   
$show['next'] = true;
   
$headinclude .= "<link rel=\"next\" href=\"{$address}&amp;page={$nextpage}\">\n";



hilaryl 07-09-2015 09:45 PM

Hi Guys,

Sorry I didn't get back earlier - missed the notification!

kh99's example of the code with the page alteration is exactly how I have it.

For darnoldy:
The hook I used was pagenav_complete, and because the code is adding data to the already implemented $headinclude variable - you don't have to add anything to your templates. Just activate the plugin and it will do the rest.

Thanks,
hilaryl

yahsuah 05-24-2017 08:26 AM

Thanks for everyone. This is working perfectly...


All times are GMT. The time now is 05:23 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02977 seconds
  • Memory Usage 1,771KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (15)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete