Jump to content

Dynamic title


cdmafra

Recommended Posts

Hello. I need to change dynamically the title of my website, but keeping the main page title and description only in main page. My website content is all generated (shown) from index.php (code bellow). I can change dynamically the title, but not keeping the main page title and description.

In the articles, I would like to present title from news_post and description of _news_desc

 

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
    <meta lang="pt" />
<meta name="author" content="Motor Racing News">
<meta name="description" content="Motor Racing News - Notícias do Desporto Motorizado">
<meta name="keywords" content="motores, formula 1, motogp, gp2 series, automobilismo, motorsport, wrc, rali, rally,dakar,motor racing news, mrn">
<meta name="viewport" content="width=device-width" /><!-- Set the viewport width to device width for mobile -->






  <title>Motor Racing News | Informações de Altas Rotações</title>




  <!-- Included CSS Files (Uncompressed) -->
  <!--
  <link rel="stylesheet" href="stylesheets/foundation.css">
  -->
  
  <!-- Included CSS Files (Compressed) -->
  <link rel="stylesheet" href="stylesheets/foundation.min.css">
  <link rel="stylesheet" href="stylesheets/app.css">
  <link rel="shortcut icon" href="images/logobar.ico" type="image/x-icon">
  
  <script src="javascripts/jquery.min.js" type="text/javascript"></script>
  <script src="javascripts/jquery-1.9.1.min.js" type="text/javascript"></script>
  <script src="javascripts/modernizr.foundation.js"></script>
</head>
<body oncontextmenu="return false;">


    <?php
      if (isset($_REQUEST["todas"]))
        {
          include("todas.php");
          return;
        }
      if (isset($_REQUEST["autospt"]))
        {
          include("autospt.php");
          return;
        }
      if (isset($_REQUEST["autosrt"]))
        {
          include("autosrt.php");
          return;
        }
      if (isset($_REQUEST["motospt"]))
        {
          include("motospt.php");
          return;
        }
      if (isset($_REQUEST["motosrt"]))
        {
          include("motosrt.php");
          return;
        }
      if (isset($_REQUEST["entrevistast"]))
        {
          include("entrevistast.php");
          return;
        }


      if (isset($_REQUEST["outrostt"]))
        {
          include("outrostt.php");
          return;
        }


      if (isset($_REQUEST["cit"]))
        {
          include("cit.php");
          return;
        }


      if (isset($_REQUEST["mmt"]))
        {
          include("mmt.php");
          return;
        }


    ?>
  <!-- Navigation -->
<?php include("menu.php");


/* atribui valor a p remetendo para a home page */
if (isset($_REQUEST["p"])) {$p=$_REQUEST["p"];} else {$p=1;} 


?>
<div class="row">
   <?php
  if (isset($_REQUEST["p"]))
    {
      $query = "SELECT * FROM nav WHERE id=".$_REQUEST["p"]."";
      $result = mysql_query($query);
      $row = mysql_fetch_array($result);
      echo "<p style='color:#ffc90d;'><b style='text-decoration:underline; color:#999;'>Página actual:</b> ";
  echo $row["element"];
echo "</p>";
?>
<?php
}
else
  echo "";




?>
</div>
  <!-- End Navigation -->




  <!-- Header -->
<?php 
if (isset($_REQUEST["guid"]))
{
    $guid = mysql_real_escape_string($_REQUEST["guid"]); // sanitize the guid 
    $query = "SELECT * FROM news WHERE news_guid='".$guid."'"; 
    $result = mysql_query($query); $row = mysql_fetch_array($result);?>
    
<div class="twelve columns">
</div>
<div class="row"><!-- Row interior-->
<div class="twelve columns">
<div class="panel">
<div class="row"><h3 class="n4"><?php echo $row["news_title"]; ?></h3>
  </div>
<p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/><?php if ($row['copyright'] <> 'Desconhecido')    echo "Copyright Imagem: " . $row['copyright'] ;?></p>
<p><?php echo $row["news_post"]; ?></p>




<!-- begin htmlcommentbox.com -->
 <div id="HCB_comment_box">A carregar os comentários...</div>


 <script type="text/javascript" language="javascript" id="hcb"> /*<!--*/ if(!window.hcb_user){hcb_user={  };} (function(){s=document.createElement("script");s.setAttribute("type","text/javascript");s.setAttribute("src", "http://www.htmlcommentbox.com/jread?page="+escape((window.hcb_user && hcb_user.PAGE)||(""+window.location)).replace("+","%2B")+"&mod=%241%24wq1rdBcg%24al/Hneesch35kyev2Dpyr1"+"&opts=478&num=10");if (typeof s!="undefined") document.getElementsByTagName("head")[0].appendChild(s);})(); /*-->*/ </script>
<script>
// This code goes ABOVE the main HTML Comment Box code!
// replace the text in the single quotes below to customize labels.
hcb_user = {
  //L10N
  comments_header : '<h4 class="n4">Comentários</h4>',
  name_label : 'Nome (pode fazer login com a sua conta Google)',
  content_label: 'Escrever o comentário aqui',
  submit : 'Comentar',
  logout_link : '<p id="data">Logout<img src="images/door_out.png" alt="[sair]" class="hcb-icon"/></p>',
  admin_link : '<p id="data">Login <img src="images/door_in.png" alt="[entrar]" class="hcb-icon"/></p>',
  no_comments_msg: '<p>Ainda ninguém comentou o artigo. Seja o primeiro!</p>',
  add: '(+) Adicone o seu comentário',
  rss: '<img src="images/feed.png" class="hcb-icon" alt="rss"/> ',
  said: 'disse:',
  prev_page:'<img src="images/arrow_left.png" class="hcb-icon" alt="[ant.]"/>',
  next_page:'<img src="images/arrow_right.png" class="hcb-icon" alt="[próx.]"/>',
  showing:'mostrar',
  to:'para',
  website_label:'website (opcional)',
  email_label:'email',
  anonymous:'Anónimo',
  mod_label:'(mod)',
  subscribe:'subscrever tópico',
  msg_thankyou:'<b>Obrigado por comentar!</b>',
  msg_approval:'(este comentário não será publicado até o aprovar)',
  msg_approval_required:'<b>Obrigado por comentar! O seu comentário aparecerá após ser aprovado por um moderador.</b>',
  
  err_bad_html:'O seu comentário contem HTML errado.',
  err_bad_email:'Por favor escreva um endereço de email válido.',
  err_too_frequent:'Deve esperar alguns segundos antes de comentar novamente.',
  err_comment_empty:'O seu comentário não foi publicado porque estava vazio!',
  //SETTINGS
  PAGE:'', // ID of the webpage to show comments for. defaults to the webpage the user is currently visiting.
  RELATIVE_DATES:true // show dates in the form "X hours ago." etc.
};
</script>


<!-- end htmlcommentbox.com -->


</div></div></div>
<div class='row'>


<?php
}
else
  switch ($p)
    {
    case 2:
      include("apresentacao.php");
    break;      
    case 3:
      include("news_principais_autosp.php");
    break;


    case 4:
      include("news_principais_autosr.php");
    break;


    case 5:
      include("news_principais_motosp.php");
    break;


    case 6:
      include("news_principais_motosr.php");
    break;
    
    case 7:
      include("news_principais_entrevistas.php");
    break;


    case 8:
      include("news_principais_outrost.php");
    break;


    case 9:
      include("news_principais_ci.php");
    break;


    case 10:
      include("news_principais_mm.php");
    break;


    default:
      include("news_principais.php"); 
    break;
  }
?>
</div>
  <!-- End Header -->


<!--RECOMENDADOS e Links -->
<?php include ("menu_links.php")
?>
<!-- End RECOMENDADOS e Links-->


<!-- Notícias Pequenas-->
<?php
  switch ($p)
    {
    case 2:
      include("pequenas_news.php");
    break;      
    case 3:
      include("pequenas_news_ap.php");
    break;


    case 4:
      include("pequenas_news_ar.php");
    break;


    case 5:
      include("pequenas_news_mp.php");
    break;


    case 6:
      include("pequenas_news_mr.php");
    break;
    
    case 7:
      include("pequenas_news_e.php");
    break;


    case 8:
      include("pequenas_news_o.php");
    break;


    case 8:
      include("pequenas_news_o.php");
    break;


    case 9:
      include("pequenas_news_ci.php");
    break;


    case 10:
      include("pequenas_news_mm.php");
    break;
    
    default:
      include("pequenas_news.php"); 
    break;
  }
?>
<!-- End Notícias Pequenas-->






  <!-- Footer -->


<?php include("rodape.php")
?>
 <!-- End Footer -->


  <!-- Included JS Files (Uncompressed) -->
  <!--
  
  <script src="javascripts/jquery.js"></script>
  
  <script src="javascripts/jquery.foundation.mediaQueryToggle.js"></script>
  
  <script src="javascripts/jquery.foundation.forms.js"></script>
  
  <script src="javascripts/jquery.event.move.js"></script>
  
  <script src="javascripts/jquery.event.swipe.js"></script>
  
  <script src="javascripts/jquery.foundation.reveal.js"></script>
  
  <script src="javascripts/jquery.foundation.orbit.js"></script>
  
  <script src="javascripts/jquery.foundation.navigation.js"></script>
  
  <script src="javascripts/jquery.foundation.buttons.js"></script>
  
  <script src="javascripts/jquery.foundation.tabs.js"></script>
  
  <script src="javascripts/jquery.foundation.tooltips.js"></script>
  
  <script src="javascripts/jquery.foundation.accordion.js"></script>
  
  <script src="javascripts/jquery.placeholder.js"></script>
  
  <script src="javascripts/jquery.foundation.alerts.js"></script>
  
  <script src="javascripts/jquery.foundation.topbar.js"></script>
  
  <script src="javascripts/jquery.foundation.joyride.js"></script>
  
  <script src="javascripts/jquery.foundation.clearing.js"></script>
  
  <script src="javascripts/jquery.foundation.magellan.js"></script>
  
  -->
  
  <!-- Included JS Files (Compressed) -->
  <script src="javascripts/jquery.js"></script>
  <script src="javascripts/foundation.min.js"></script>
  
  <!-- Initialize JS Plugins -->
  <script src="javascripts/app.js"></script>
  <script type="text/javascript">
     $(window).load(function() {
         $('#featured').orbit();
     });
</script>
<!-- Quantcast Tag -->
<script type="text/javascript">
var _qevents = _qevents || [];


(function() {
var elem = document.createElement('script');
elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";
elem.async = true;
elem.type = "text/javascript";
var scpt = document.getElementsByTagName('script')[0];
scpt.parentNode.insertBefore(elem, scpt);
})();


_qevents.push({
qacct:"p-2G4Bk55Wj3bsE"
});
</script>


<noscript>
<div style="display:none;">
<img src="//pixel.quantserve.com/pixel/p-2G4Bk55Wj3bsE.gif" border="0" height="1" width="1" alt="Quantcast"/>
</div>
</noscript>
<!-- End Quantcast tag -->
</body>


</html>
 
Link to comment
Share on other sites

I am not going to read through all of that code. But, to do what you want you should:

 

Run all the "logic" of your code first and determine what the output should be - THEN create the output. As part of this process you can determine what the appropriate title should be. Do, not intermix logic within the output like this:

 

<div id="status">
<?php
if($active == true)
{
    echo "Your account is active";
}
else
{
    echo "Your account is not active";
}
?>
</div>

 

Instead, run the logic before you ever start the HTML output. Store the output in various variables and include those in the output.

 

<?php
if($active == true)
{
    $activeText = "Your account is active";
}
else
{
    $activeText = "Your account is not active";
}
 
 
?>
<html>
. . .
 
<div id="status"><?php echo $activeText; ?></div>
Link to comment
Share on other sites

<?php
$page = $_GET['page'];
$selection = explode(".", $page);
	if ($page == ""){
		include_once('pages/dashboard.sidebar.php');
		include_once('pages/dashboard.dashboard.php');
	}
	else if (($page != "") && file_exists('pages/'.$page.'.php')){
		include_once('pages/'.$selection[0].'.sidebar.php');
		include_once('pages/'.$page.'.php');
	}
	else {
		include_once('pages/error.php');
	}		
?>

Sorry, this is off topic but Instead of creating every possible page name why not put a loop in there and then redirect based on input from href's and $page variable. Then redirect, if the page doesn't exist then it puts them at an error screen.

Edited by Crew-Portal
Link to comment
Share on other sites

 

I am not going to read through all of that code. But, to do what you want you should:

 

Run all the "logic" of your code first and determine what the output should be - THEN create the output. As part of this process you can determine what the appropriate title should be. Do, not intermix logic within the output like this:

<div id="status">
<?php
if($active == true)
{
    echo "Your account is active";
}
else
{
    echo "Your account is not active";
}
?>
</div>

Instead, run the logic before you ever start the HTML output. Store the output in various variables and include those in the output.

<?php
if($active == true)
{
    $activeText = "Your account is active";
}
else
{
    $activeText = "Your account is not active";
}
 
 
?>
<html>
. . .
 
<div id="status"><?php echo $activeText; ?></div>

 

How can it help me in my case, I'm not seeing...

Link to comment
Share on other sites

How can it help me in my case, I'm not seeing...

 

I thought that I was pretty obvious. Run all your logic FIRST to determine what page you are on and what you want the title to be. THEN output the page using the title that you defined in the logic run previously

 

 

<?php
switch($page)
{
    case 'page1':
        $title = "This is the title for page 1";
        break;
    case 'page2':
        $title = "This is the title for page 2";
        break;
    case 'page3':
        $title = "This is the title for page 3";
        break;
}
 
?>
<html>
<head>
<title><?php echo $title; ?></title>
<head>
<body>
Link to comment
Share on other sites

 

I thought that I was pretty obvious. Run all your logic FIRST to determine what page you are on and what you want the title to be. THEN output the page using the title that you defined in the logic run previously

<?php
switch($page)
{
    case 'page1':
        $title = "This is the title for page 1";
        break;
    case 'page2':
        $title = "This is the title for page 2";
        break;
    case 'page3':
        $title = "This is the title for page 3";
        break;
}
 
?>
<html>
<head>
<title><?php echo $title; ?></title>
<head>
<body>

 

Sorry, I not explained my situation clearly. I have only one page generating all site throug MySQL db... 

Edited by cdmafra
Link to comment
Share on other sites

Sorry, I not explained my situation clearly. I have only one page generating all site throug MySQL db... 

 

Yes, I understood that. And the answer I gave will solve your problem. You must have logic in the index.php page to determine what content to show, correct? In that logic include code to determine what the title should be and output that. I don't know how else to explain it. I've also provided mock code to help you understand as well. Good luck.

Link to comment
Share on other sites

Yes, I understood that. And the answer I gave will solve your problem. You must have logic in the index.php page to determine what content to show, correct? In that logic include code to determine what the title should be and output that. I don't know how else to explain it. I've also provided mock code to help you understand as well. Good luck.

 

Thank you. I think it's not possible to do what I'm trying to do. This works with pages in what "$pages" variable are usable. However, when I generate the post, I am not asking by "$pages", but for guid in news table. How can I, in this case, to get the news_title row to define page title?

 

<?php 
if (isset($_REQUEST["guid"]))
{
    $guid = mysql_real_escape_string($_REQUEST["guid"]); // sanitize the guid 
    $query = "SELECT * FROM news WHERE news_guid='".$guid."'"; 
    $result = mysql_query($query); $row = mysql_fetch_array($result);?>
    
<div class="twelve columns">
</div>
<div class="row"><!-- Row interior-->
<div class="twelve columns">
<div class="panel">
<div class="row"><h3 class="n4"><?php echo $row["news_title"]; ?></h3>
  </div>
<p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT<br/><?php if ($row['copyright'] <> 'Desconhecido')    echo "Copyright Imagem: " . $row['copyright'] ;?></p>
<p><?php echo $row["news_post"]; ?>
</p>
Link to comment
Share on other sites

I am not going to rewrite your script (which is what it is going to take). Your page is a mish-mash of a lot of things that really don't follow a logical flow and it cannot be done with how you have built the page. I only provided the basic logic on how to accomplish what you want. As I said, you already have a bunch of logic to determine what you are going to display. Within that logic you need to define a page title that will be included as part of the output. But, you can't because the page is intermixing the logic (PHP) and the presentation (HTML).

 

You have to output the title at the beginning of the HTML page. But, you output the header of your page before you ever start the logic of what will be displayed on the page. As I stated, you need to run all of your logic before you ever start the output.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.