Author Topic: Link & location of a new or moved subpage after its parent's seo-title changed  (Read 842 times)

Offline gokcer

  • Posts: 94
After the seo-title of a parent page is changed without changing the menu title:
When a new sub page added (or moved) under it, old seo-title (which generated from its title) is set as the folder name inside the subpage's link and location. Because the folder names in link tree is generated with titles. This causes different folders for the siblings under pages directory.

Why don't we use the parent link for a more correct structure?
(This may also be related to http://project.WebsiteBaker.org/issues/37)

Please warn me if I am wrong (inside admin/pages/add.php-121 and admin/pages/settings2.php-220):

Code: [Select]
/* comment out old code that generate links from parent titles
        $parent_section = '';
        $parent_titles = array_reverse(get_parent_titles($parent));
        foreach($parent_titles AS $parent_title) {
                $parent_section .= page_filename($parent_title).'/';
        }
        if($parent_section == '/') { $parent_section = ''; }
        $link = '/'.$parent_section.page_filename($title); // -> this is ($seo_title) for settings2.php
*/
// new code to get parent link and put inside the sub page link
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.intval($parent);
        $parent_link = $database->get_one($sql);
        $parent_section =  $parent_link.'/';
        if($parent_section == '/') { $parent_section = ''; }
        $link = $parent_section.page_filename($title); -> this is ($seo_title) for settings2.php


Offline jacobi22

  • Posts: 5836
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
my private position.... the problem is reported (your link to the project) and i'll wait for a official solution for that

i test your code, but if add a new subpage to a renamed parent, it add's this page into the root of the page directory - so something goes wrong  :|

Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline gokcer

  • Posts: 94
Thanks for testing.
Everything looks ok on my tests, but I found a "double slashes" problem on the code which may cause the problem on your server so I renewed it.
And I tested it with the following data:
Parent page's menu title: "Parent Page"
Parent page's changed seo title: "new_seo_name"
Sub page's title: "Sub Page"

admin/pages/add.php (121) (results near lines):

Code: [Select]
/* comment out old code that generate links from parent titles
        $parent_section = '';
        $parent_titles = array_reverse(get_parent_titles($parent));
        foreach($parent_titles AS $parent_title)
        {
                $parent_section .= page_filename($parent_title).'/';
        }
        if($parent_section == '/') { $parent_section = ''; }
        $link = '/'.$parent_section.page_filename($title);
        $filename = WB_PATH.PAGES_DIRECTORY.'/'.$link.PAGE_EXTENSION;
        make_dir(WB_PATH.PAGES_DIRECTORY.'/'.$parent_section);
*/
// the fix
        $sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.intval($parent);
        $parent_link = $database->get_one($sql); // -----> "/new_seo_name"
        $link = $parent_link.'/'.page_filename($title);//  -----> "/new_seo_name/sub-page" (this one goes to database)
        $filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION; // -----> "[WB_PATH]pages/new_seo_name/sub-page.php"
        make_dir(WB_PATH.PAGES_DIRECTORY.$parent_link); // -----> "[WB_PATH]pages/new_seo_name"
// end fix

admin/pages/settings2.php (220):
Code: [Select]
/* comment out old code that generate links from parent titles
        $parent_section = '';
        $parent_titles = array_reverse(get_parent_titles($parent));
        foreach($parent_titles as $parent_title) {
                $parent_section .= page_filename($parent_title).'/';
        }
        if( $parent_section == '/' ) { $parent_section = ''; }
        $link = '/'.$parent_section.page_filename($seo_title);
        $filename = WB_PATH.PAGES_DIRECTORY.'/'.$parent_section.page_filename($seo_title).PAGE_EXTENSION;
*/
// the fix
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.intval($parent);
        $parent_link = $database->get_one($sql);
        $link = $parent_link.'/'.page_filename($seo_title);
        $filename = WB_PATH.PAGES_DIRECTORY.$parent_link.'/'.page_filename($seo_title).PAGE_EXTENSION;
// end fix

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 3010
  • Gender: Female
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf Hirn vom Himmel !

 

postern-length