Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Title - dynamiczny układ
Forum PHP.pl > Forum > Przedszkole
aglar
Witam, jestem zielony z php, ale mysle ze przy waszej pomocy bede mogl zmodyfikowac jedna rzecz. Na swoim forum mam takie title:

  1. <?php
  2. <title>', $context['page_title'], '</title>;
  3. ?>


I jest tak ze dla kazdego page mam inny title. Jednakze title z glownej strony, chcialbym miec inne niz z page_title. Czy mozecie mi pomoc ulozyc taki kod, ktory by pozwalal na pozostawienie obecnego ustawienia title a jednoczesnie na mozliwosc ulozenia osobnego title dla glownej strony (index.php)?
Spawnm
Proszę dodać tagi do tematu.


zobacz:
  1. <?php
  2. print_r($_SERVER);
  3. ?>
cojack
np mógłbyś to zrobić tak:

  1. <?php
  2. if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  3. {
  4.  echo '<title>Title dla strony głównej ' . $context['page_title'] . ' albo z tej strony</title>';
  5. }
  6. else
  7. {
  8.  echo '<title>' . $context['page_title'] . </title>;
  9. }
  10. ?>
aglar
Dziekuje za tak szybka i konkretna pomoc!

Tagi zostaly dodane smile.gif

@cojack: Po dodaniu Twojego kodu pojawil sie blad, pewnie wynika to z tego ze brakuje jakiegos `. a moze {} winksmiley.jpg

Moglbys rzucic okiem na ten blad?

Template Parse Error!
There was a problem loading the /index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

  1. <?php
  2. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in index.template.php on line 81
  3. 72:     <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
  4. 73:     <script language="JavaScript" type="text/JavaScript" src="http://www.xyz.pl/phpTACookie.js"></script>
  5. 74:     <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
  6. 75:         var smf_theme_url = "', $settings['theme_url'], '";
  7. 76:         var smf_images_url = "', $settings['images_url'], '";
  8. 77:         var smf_scripturl = "', $scripturl, '";
  9. 78:         var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  10. 79:         var smf_charset = "', $context['character_set'], '";
  11. 80:     // ]]></script>
  12. 81: if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  13. 82: {
  14. 83:  echo '<title>custom title ' . $context['page_title'] . ' albo z tej strony</title>';
  15. 84: }
  16. 85: else
  17. 86:{
  18. 87: echo '<title>' . $context['page_title'] . </title>;
  19. 88:}
  20. 89:
  21. 90:    //
  22. ?>
krzysiekk
witam
masz cos takiego:
  1. <?php
  2. src= " ', $settings['default_theme_url'], '/script.js?fin11"></script>
  3. ?>

a powinno byc chyba
  1. <?php
  2. src= " '. $settings['default_theme_url']. '/script.js?fin11"></script>
  3. ?>

i to w wszystkich zmiennych ktore dolanczasz w tym JS
ale za mało kodu dałes
aglar
Nie nie panowie, ten kod z JS dzialal prawidlowo, wszystko bylo z nim ok.
Dalem po prostu wiekszy odcinek kodu, zeby czegos nie pominac.

Wczesniej bylo tak:

  1. <?php
  2. <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
  3.        var smf_theme_url = "', $settings['theme_url'], '";
  4.        var smf_images_url = "', $settings['images_url'], '";
  5.        var smf_scripturl = "', $scripturl, '";
  6.        var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  7.        var smf_charset = "', $context['character_set'], '";
  8.    // ]]></script>
  9.    <title>', $context['page_title'], '</title>;
  10.  
  11.    // The ?finll part of this link is just here to make sure browsers don't cache it wrongly.
  12.     echo
  13. ?>


I zmienilem zgodnie ze wskazowkami na:


  1. <?php
  2. <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
  3.        var smf_theme_url = "', $settings['theme_url'], '";
  4.        var smf_images_url = "', $settings['images_url'], '";
  5.        var smf_scripturl = "', $scripturl, '";
  6.        var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  7.        var smf_charset = "', $context['character_set'], '";
  8.    // ]]></script>
  9.    if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  10. {
  11. echo '<title>Title dla strony głównej ' . $context['page_title'] . ' albo z tej strony</title>';
  12. }
  13. else
  14. {
  15. echo '<title>' . $context['page_title'] . </title>;
  16. }
  17.  
  18.    // The ?finll part of this link is just here to make sure browsers don't cache it wrongly.
  19.     echo
  20. ?>


I wtedy wyskakuje blad w lini:

  1. <?php
  2. if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  3. ?>


:/
golaod
A możesz dać większą część kodu bo tak szczerze to ja do tej pory nie wiem jak u Ciebie się php wykonuje pomiędzy tym html'em. Na pewno nie za pomocą '.$zmienna.' bo u Ciebie są przecinki. Używasz jakiegoś parsera ?
Dritter
Znaczniki otwarcia i zamknięcia -:-

// ]]></script>


Usuń "//" z tej linijki.
aglar
Oczywiscie. Idąc od góry:

  1. <?php
  2.  
  3. // Initialize the template... mainly little settings.
  4. function template_init()
  5. {
  6.    global $context, $settings, $options, $txt;
  7.  
  8.    /* Use images from default theme when using templates from the default theme?
  9.         if this is 'always', images from the default theme will be used.
  10.         if this is 'defaults', images from the default theme will only be used with default templates.
  11.         if this is 'never' or isn't set at all, images from the default theme will not be used. */
  12.    $settings['use_default_images'] = 'never';
  13.  
  14.    /* What document type definition is being used? (for font size and other issues.)
  15.         'xhtml' for an XHTML 1.0 document type definition.
  16.         'html' for an HTML 4.01 document type definition. */
  17.    $settings['doctype'] = 'xhtml';
  18.  
  19.    /* The version this template/theme is for.
  20.         This should probably be the version of SMF it was created for. */
  21.    $settings['theme_version'] = '1.1.5';
  22.  
  23.    /* Set a setting that tells the theme that it can render the tabs. */
  24.    $settings['use_tabs'] = false;
  25.  
  26.    /* Use plain buttons - as oppossed to text buttons? */
  27.    $settings['use_buttons'] = false;
  28.    $settings['use_image_buttons'] = true;
  29.    /* Show sticky and lock status seperate from topic icons? */
  30.    $settings['seperate_sticky_lock'] = true;
  31.  
  32. }
  33.  
  34. // The main sub template above the content.
  35. function template_main_above()
  36. {
  37.    global $context, $settings, $options, $scripturl, $txt, $language, $modSettings;
  38.  
  39.    // Show right to left and the character set for ease of translating.
  40.    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
  42.    <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  43.    <meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
  44.    <meta name="robots" content="noindex" />', '
  45.    <meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
  46.    <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
  47.    <script language="JavaScript" type="text/JavaScript" src="http://www.xyz.pl/phpTACookie.js"></script>
  48.    <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
  49.        var smf_theme_url = "', $settings['theme_url'], '";
  50.        var smf_images_url = "', $settings['images_url'], '";
  51.        var smf_scripturl = "', $scripturl, '";
  52.        var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  53.        var smf_charset = "', $context['character_set'], '";
  54.    // ]]></script>
  55.    if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  56. {
  57. echo '<title>Title dla strony głównej ' . $context['page_title'] . ' albo z tej strony</title>';
  58. }
  59. else
  60. {
  61. echo '<title>' . $context['page_title'] . </title>;
  62. }
  63.  
  64.    // The ?finll part of this link is just here to make sure browsers don't cache it wrongly.
  65.     echo '
  66.    <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />
  67.    <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?fin11" media="print" />
  68.  
  69.    <!--[if lte IE 6]>
  70.        <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/ie6lte.css?fin11" />
  71.    <![endif]-->';
  72. ?>


Nie uzywam parsera, bo jak pisalem jestem zielony, ale chetnie zaglebie sie w swiat php zaczynajac od tego watku smile.gif
Dritter
Przenieś </script> do następnej linijki.
Ewentualnie usuń komentarz (//) z tej linii.
aglar
Cytat(Dritter @ 1.07.2009, 15:46:46 ) *
Przenieś </script> do następnej linijki.
Ewentualnie usuń komentarz (//) z tej linii.


Myslalem ze to pomoglo, ale jednak nie. Wydaje mi sie ze szukanie dziur w JS nie ma pomoze, bo JS dzialal ok, cos jest nie tak od lini 82
czyli
  1. <?php
  2. if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  3. ?>
krzysiekk
  1. <?php
  2.  
  3. // Initialize the template... mainly little settings.
  4. function template_init()
  5. {
  6.   global $context, $settings, $options, $txt;
  7.  
  8.   /* Use images from default theme when using templates from the default theme?
  9.        if this is 'always', images from the default theme will be used.
  10.        if this is 'defaults', images from the default theme will only be used with default templates.
  11.        if this is 'never' or isn't set at all, images from the default theme will not be used. */
  12.   $settings['use_default_images'] = 'never';
  13.  
  14.   /* What document type definition is being used? (for font size and other issues.)
  15.        'xhtml' for an XHTML 1.0 document type definition.
  16.        'html' for an HTML 4.01 document type definition. */
  17.   $settings['doctype'] = 'xhtml';
  18.  
  19.   /* The version this template/theme is for.
  20.        This should probably be the version of SMF it was created for. */
  21.   $settings['theme_version'] = '1.1.5';
  22.  
  23.   /* Set a setting that tells the theme that it can render the tabs. */
  24.   $settings['use_tabs'] = false;
  25.  
  26.   /* Use plain buttons - as oppossed to text buttons? */
  27.   $settings['use_buttons'] = false;
  28.   $settings['use_image_buttons'] = true;
  29.   /* Show sticky and lock status seperate from topic icons? */
  30.   $settings['seperate_sticky_lock'] = true;
  31.  
  32. }
  33.  
  34. // The main sub template above the content.
  35. function template_main_above()
  36. {
  37.   global $context, $settings, $options, $scripturl, $txt, $language, $modSettings;
  38.  
  39.   // Show right to left and the character set for ease of translating.
  40.   echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
  42.   <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
  43.   <meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
  44.   <meta name="robots" content="noindex" />', '
  45.   <meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
  46.   <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
  47.   <script language="JavaScript" type="text/JavaScript" src="http://www.xyz.pl/phpTACookie.js"></script>
  48.   <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
  49.       var smf_theme_url = "', $settings['theme_url'], '";
  50.       var smf_images_url = "', $settings['images_url'], '";
  51.       var smf_scripturl = "', $scripturl, '";
  52.       var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
  53.       var smf_charset = "', $context['character_set'], '";
  54.   // ]]></script>';
  55.   if(basename($_SERVER['SCRIPT_FILENAME']) == 'index.php')
  56. {
  57. echo '<title>Title dla strony głównej ' . $context['page_title'] . ' albo z tej strony</title>';
  58. }
  59. else
  60. {
  61. echo '<title>' . $context['page_title'] . '</title>';
  62. }
  63.  
  64.   // The ?finll part of this link is just here to make sure browsers don't cache it wrongly.
  65.    echo '
  66.   <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />
  67.   <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?fin11" media="print" />
  68.  
  69.   <!--[if lte IE 6]>
  70.       <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/ie6lte.css?fin11" />
  71.   <![endif]-->';
  72. }
  73. ?>
  74.  
  75. zobacz czy nasz dobrze koniec funkcji wstawiony
cojack
Jak mogłeś wrzucić instrukcję warunkową do funkcji (tutaj echo) wyświetlającego kod html... powyższy kod musi działać prawidłowo. Następnym razem podawaj cały kod.
aglar
Cytat(cojack @ 1.07.2009, 16:46:22 ) *
Jak mogłeś wrzucić instrukcję warunkową do funkcji (tutaj echo) wyświetlającego kod html... powyższy kod musi działać prawidłowo. Następnym razem podawaj cały kod, bo nawet ten co podałeś na początku był nie poprawny, przecinki zamiast kropek.


Uff, teraz zadzialo, dziekuje wszystkim za dotychczasowa pomoc. Problemy wynikaja stad, ze moja wiedza jest minimalna jesli chodzi o php, i nie znam sie na skladni.

Jednakze cos dalej jest nie tak, gdyz custom title pojawia sie na wszystkich stronach. Moze wynika to z tego, ze skrypt forum wszedzie "widzi" index.php?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.