General Community > Development 2.10.x

Link & location of a new or moved subpage after its parent's seo-title changed

(1/1)

gokcer:
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: ---/* 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

--- End code ---

Gast:
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  :|

gokcer:
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: ---/* 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

--- End code ---

admin/pages/settings2.php (220):

--- Code: ---/* 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

--- End code ---

DarkViper:
see Re: Root Parent IDs of Root Pages

Navigation

[0] Message Index

Go to full version