Jump to content

Recommended Posts

Hi all,

 

I am new, so please bear with me.  I am having some difficulty figuring this out.  What I would like to do is use PHP to determine which template I should serve based on certain criterions of an item in the database.  For example, if I add a certain article and it is associated with an item (ex: a movie), I would like to serve up a template where it would have movie-specific information on the page (ex: name of movie, genre, length of time, etc.).  On the other hand, if the article I add is not associated with an item, then it would use a _different_ template without all the specific information.

 

My best guess so far is to have some PHP code that uses an if-else loop on the article to see if the "associated item" field is filled out.

 

The question is, how should I go about implementing this?  Are there any other methods better than the above?  Any help would be appreciated.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/53184-determining-which-template-to-use/
Share on other sites

Yes, the articles would be stored in a database.  I don't mean to change the template based on a type (ex: movie, music, games), but more based on the association between the article and its parent item.  So instead, would I be able to adapt this to the following:

 

Ex: When I add an article, instead of 'type', the row or column is called something like 'parent_item' and it would be the name of the movie.  Then when the page loads, I call for template-1.php if the 'parent_item' field is populated.  If it is not populated, I call for template-2.php (both are arbitrarily named).

 

When you "call" and filter based on the results of 'parent_item', do you mean use of if-else statements in the PHP code?

 

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.