Jump to content

Pass Parameters From Index.php Tag To Header.php Meta


donrobertito

Recommended Posts

Hello there!

 

I'm such a beginner in php coding, i don't know the trick yet. My question is:

 

I have a site, the main files are header.php; index.php; footer.php.

I include header and footer in index php

 

The index.php contains the articles, with tags. I want to pass the tags form articles to header.php as meta information.

I get the tags from a database query.

 

How can i do this method?

 

Thanks: Robert

Link to comment
Share on other sites

By passing them as variables into the header.php after you include it.

Thanks! But can yopu be a bit more precise? With a tiny example?

 

My code looks like this at the tags:

 

 

<p>Tags <?php

for ($i = 0; $i < $count; $i++) {

echo '<a href="index.php?p=tag&tag='.$article[$i]->tag_word.'">'.$article[$i]->tag_word.'</a>';

if ($i != $count-1)

echo ", ";

}?></p><br />

 

How can i pass these to header?

Link to comment
Share on other sites

  • 2 months later...

Dear Muddy_Funster,

 

I come back to this project, I had so much to do, that I had no time for this, but this is really important to me to learn php! So than you for your help.

There is something not clear with your suggestion:

- I think, there is one "{" is missing, but I found his place...

- As you can see, the "tag" is used in the "Tags:" line on the bottom of the page. Is this a good idea to use it in your example?

- You defined multiple times the $tags variable. Is this rigth?

 

Your example is not working for me...

 

Thanks: Robert

Link to comment
Share on other sites

If you are defining or retrieving data in index.php, after the point where you have included header.php, that data does not exist at the time the header.php code is executed. Programming does not have the ability to go back in time.

 

Using php include statements to paste together a page can only produce a very basic page.

 

To do what you need, you must switch to a concept of having all the main php 'business' logic first on the page. That php code produces content that is stored in variables (different variables for the title, meta tags, navigation links, content...) Then you output your HTML document at the end of the code, echoing the php variables at the correct point to give you the output that you want.

Edited by PFMaBiSmAd
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.