WebsiteBaker Community Forum
General Community => Development 2.10.x => Topic started by: gokcer on July 15, 2017, 02:31:12 AM
-
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 (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):
/* 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
-
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 :|
-
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):
/* 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):
/* 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
-
see Re: Root Parent IDs of Root Pages (https://forum.WebsiteBaker.org/index.php/topic,30391.msg211879.html#msg211879)