saint Posted May 27, 2007 Share Posted May 27, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/53184-determining-which-template-to-use/ Share on other sites More sharing options...
dj-kenpo Posted May 27, 2007 Share Posted May 27, 2007 are the articles stored in a database? if so, add an extra row to the table called 'type'. on your edit page use a drop down for movie, etc. then when the page loads do a call for different css files depending on the reults of 'type'. Quote Link to comment https://forums.phpfreaks.com/topic/53184-determining-which-template-to-use/#findComment-262752 Share on other sites More sharing options...
saint Posted May 27, 2007 Author Share Posted May 27, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/53184-determining-which-template-to-use/#findComment-262822 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.