Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HOW check if exist some page slug ???
#1
I need check if exist some page slug.


example: 

exist_page('page-21');

Please help Thanks.
Reply
#2
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!
Reply
#3
(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.
Reply




Users browsing this thread: 1 Guest(s)