Different headlines for same article appearing on list pages depending on Category selected by public end user????

2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 17, 2012   (RSS)

Re: [davidcmsb] Different headlines for same article appearing on list pages depending on Category selected by public end user????

By Jason - July 17, 2012

Hi David,

That is an interesting problem. As you said, you could approach it where you had a separate header field in your article for every category. This isn't very flexible though, as every time you add a new category (or delete one) you need to make a change in your article section and possibly update your code. It's also a large number of fields to maintain, most of which will always be blank.

The best solution, I think, would to have a 3rd section where you can create different titles for articles based on category.

For example, you could call it something like "article_titles_by_category". In it you would need 3 fields:
- list field selecting an article (based on record num)
-list field selecting a single category from your category section (based on record num)
-title field.

The trick is getting the the right category number. From your examples, it looks like category is a variable in your URL, is that right? If so, then this should be pretty easy. In your foreach loop, you try to find a record in article_title_by_category, if you can't, then you use the article title field as a default.

EXAMPLE:

<?php foreach ($articles as $article): ?>
<?php $categoryTitle = mysql_get("article_title_by_category", null, "article = '".$article['num']."' AND category = '".intval(@$_REQUEST['category'])."'");?>

<?php if ($categoryTitle): ?>
<h1><?php echo $categoryTitle['title'];?></h1>
<?php else: ?>
<h1><?php echo $article['title'];?></h1>
<?php endif ?>

<?php endforeach ?>


Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/