WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.8 is now available!


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.12.x) »
  • General Help & Support »
  • News module rel = prev next
  • Print
Pages: [1]   Go Down

Author Topic: News module rel = prev next  (Read 8513 times)

Offline dbs

  • Betatester
  • **
  • Posts: 8920
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
News module rel = prev next
« on: May 12, 2018, 11:23:23 AM »
Hello, for SEO reasons, if news have pagination, i want in the <head>:
Code: [Select]
<link rel="prev(or next)" href="?p=n">
My try
In news module view.php added 2 classes (news-next-page, news-prev-page) in lines 152 to 171 (4 times) for the generated prev-next-links.

Created a droplet and added it to the settings footer of news module
Code: [Select]
<?php // this line is only for color reasons, don't copy this

// adds <link rel="prev|next" href="?p=nn"> at the end of the <head>
// only if news has pagination
// for SEO reasons (dynamic parameters) 

preg_match("#class=\"news-next-page\" href=\"([^\"]*)\"#",$wb_page_data,$matches);
$page  = !empty($matches[1]) ? '<link rel="next" href="'.$matches[1].'">' : '';

preg_match("#class=\"news-prev-page\" href=\"([^\"]*)\"#",$wb_page_data,$matches);
$page .= !empty($matches[1]) ? '<link rel="prev" href="'.$matches[1].'">' : '';

$wb_page_data = str_replace('</head>',"\n\t".$page.'</head>',$wb_page_data);
return 
true;

This works, but i know it is no good code.
Maybe somebody can optimize it. :-)
Logged
https://onkel-franky.de

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 3087
  • Gender: Female
Re: News module rel = prev next
« Reply #1 on: May 13, 2018, 04:52:33 PM »
Code: [Select]
<?php // this line is only for color reasons, don't copy this

if (preg_match('#class=\"news-next-page\"[^>]+?href=\"([^\"]*)\"#', $wb_page_data, $matches)) {
    
$page  = '<link rel="next" href="'.$matches[1].'">';
}

if (
preg_match('#class=\"news-prev-page\"[^>]+?href=\"([^\"]*)\"#', $wb_page_data, $matches)) {
    
$page .= '<link rel="prev" href="'.$matches[1].'">';
}

$wb_page_data = str_replace('</head>',"\n\t".$page.'</head>',$wb_page_data);
return 
true;
:-)
Logged
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"We need education to cope with digitalization - and NOT the digitalization of education.!"

Tägliches Stoßgebet: Oh Herr, wirf Hirn vom Himmel !

Offline dbs

  • Betatester
  • **
  • Posts: 8920
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: News module rel = prev next
« Reply #2 on: May 13, 2018, 06:31:01 PM »
Looks a little bit better and shorter. Thx.
2 in 1 is maybe also possible. Will try it.
Logged
https://onkel-franky.de

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 3087
  • Gender: Female
Re: News module rel = prev next
« Reply #3 on: May 13, 2018, 11:44:48 PM »
2 in 1  only?
if, then n in 1 please  ;-)
Code: [Select]
<?php // this line is only for color reasons, don't copy this

    
$sPage = '';
    
$sPattern = '/class=\"news-(?P<rel>next|prev)-page\"[^>]+?href=\"(?P<url>[^\"]*)\"/siu';
    if (
false !== preg_match_all($sPattern, $wb_page_data, $aMatches, PREG_SET_ORDER)) {
        foreach (
$aMatches as $aMatch) {
            
$sPage .= '<link rel="'.$aMatch['rel'].'" href="'.$aMatch['url'].'">'.PHP_EOL;
        }
        
$wb_page_data = str_replace('</head>', "\n\t".$sPage.'</head>', $wb_page_data);
    }
    return 
true;
Logged
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"We need education to cope with digitalization - and NOT the digitalization of education.!"

Tägliches Stoßgebet: Oh Herr, wirf Hirn vom Himmel !

Offline dbs

  • Betatester
  • **
  • Posts: 8920
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: News module rel = prev next
« Reply #4 on: May 14, 2018, 08:21:45 AM »
Looks professional and works. Thank you very much  (Y)
I had tried also with preg_match_all and foreach, but ... forget it.  :-)
Logged
https://onkel-franky.de

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.12.x) »
  • General Help & Support »
  • News module rel = prev next
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2