GetSimple Support Forum

Full Version: HOW check if exist some page slug ???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need check if exist some page slug.


example: 

exist_page('page-21');

Please help Thanks.
To check page exist you can use global $pagesArray variable, it contains cached page data:

Code:
global $pagesArray;
if(isset($pagesArray[$slug])) echo 'Page exist';
else echo 'Page does not exist';

Another, quicker option would be to check it manually with native file_exist() PHP method, for example:

Code:
if(file_exists(GSDATAPAGESPATH.$slug.'.xml')) echo 'Page exist';
else echo 'Page does not exist';

PS. Do not forget to sanitize the user input!
(2017-04-07, 18:20:21)Bigin Wrote: [ -> ]To check page exist you can use global $pagesArray variable, it contains cached page data:

Code:
global $pagesArray;
if(isset($pagesArray[$slug])) echo 'Page exist';
else echo 'Page does not exist';

Another, quicker option would be to check it manually with native file_exist() PHP method, for example:

Code:
if(file_exists(GSDATAPAGESPATH.$slug.'.xml')) echo 'Page exist';
else echo 'Page does not exist';

PS. Do not forget to sanitize the user input!

Nice solution Smile 
I use this for my template functions.php  
Thank you.