astarmathsandphysics Posted February 12, 2015 Share Posted February 12, 2015 I have several websites using the same basic script and I have the same problem in each - all the page titles are the same. see http://courseworkbank.info/?dir=GCSE the page title here is COURSEWORKBANK.INFO I would like it to be GCSE For http://courseworkbank.info/?dir=GCSE/Biology I would like it to be GCSE - Biology How do I do this? Am using a simple index.php file to load everything. Quote Link to comment Share on other sites More sharing options...
GuitarGod Posted February 12, 2015 Share Posted February 12, 2015 Your structure seems to follow a pattern of '?dir=DIR1/DIR2/DIR3 etc, and you want to display a title of DIR1 - DIR2 - DIR3, the following code should suffice. if ( isset( $_GET['dir'] ) ) { $explode = explode( '/', $_GET['dir'] ); $dir_count = count( $explode ); $title = ''; $i = 1; foreach ( $explode as $k ) { $suffix = ( $i == $dir_count ) ? '' : ' - '; // Seperate the directory names with - $title .= $k . $suffix; $i++; } } If you place this code before your title code (e.g. <title>COUR...</title>) Then change your title code to <title><?= $title; ?></title>, it should work. Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 12, 2015 Author Share Posted February 12, 2015 No I dont get a title at all Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 12, 2015 Author Share Posted February 12, 2015 Experimenting with your code now Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 12, 2015 Author Share Posted February 12, 2015 I can't make it work. Not an expert even good programmer. Quote Link to comment Share on other sites More sharing options...
Tom10 Posted February 12, 2015 Share Posted February 12, 2015 Have you tried using preg_match / Regular Expressions to take GCSE and Biology out of the URL and then echo the result? Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 12, 2015 Author Share Posted February 12, 2015 I will read up on that. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted February 12, 2015 Share Posted February 12, 2015 How about showing the code where you are generating your current titles? Very difficult to give accurate/good answers without that. Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 16, 2015 Author Share Posted February 16, 2015 here is the title code $_CONFIG['main_title'] = "A Star Maths and Physics Notes"; <title><?php if(EncodeExplorer::getConfig('main_title') != null) print EncodeExplorer::getConfig('main_title'); ?></title> Quote Link to comment Share on other sites More sharing options...
raphael75 Posted February 16, 2015 Share Posted February 16, 2015 Replace what you have with this: if(isset($_GET['dir'])){ echo '<title>' . $_GET['dir'] . '</title>'; } else{ echo '<title>A Star Maths and Physics Notes</title>'; } 1 Quote Link to comment Share on other sites More sharing options...
astarmathsandphysics Posted February 16, 2015 Author Share Posted February 16, 2015 Whey that works. Well on the way now to saying bye to html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.