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)
By davidcmsb - July 16, 2012
I’m stumped on this. I’m wondering if it is even possible, and if it is, just how to do it.
I want to make the headlines that appear for the articles, both in the list pages and on the article page itself, change depending on the CMSB Category.
Here’s what I mean specifically:
The articles are summaries of baseball games. I’ve set things up in CMSB so that the articles get “tagged” by assigning them to one or more of several CMSB Categories I’ve set up in CMSB for what type of game it was. (I use a multi-select list in CMSB Admin for this.) For example the CMSB Categories and Sub-Categories for game types I’ve set up in CMSB Admin are:
-Game Summaries:
—Pitching Duels
—Slug Fests
—Extra Innings
[note: my system actually has dozens of these subcategories, so there’s lots of them]
So, if a game was only a Pitching Duel, the article for it gets assigned to that CMSB Category. When a public end user of the site selects that Category from the menu on the public page, the article for this game appears in the article list (along with all the other articles also tagged with this CMSB Category).
And, if a game was both a Pitching Duel and an Extra Innings game also, the article for it gets assigned to both of those CMSB Categories. This way, that article appears on the list page if either CMSB Category — Pitching Duel or Extra Innings — is selected by the public end user viewing the site.
I’ve got the foregoing set up and running fine.
BUT here’s the problem I’m trying to solve now:
Using the last example above, i.e., an article that’s assigned to two or more CMSB Categories (such as one that’s assigned to both, e.g., the Pitching Duel and the Extra Innings CMSB Categories), will appear on on both these list pages with the same headline. That’s a problem. Here’s an example why.
If an article about a game was both a Pitching Duel and also an Extra Innings type game, the single headline for that article I write when creating the article in CMSB Admin (there is a filed named ‘headline’) might just be about only one of these aspects — e.g., “Giants Win In Extra Innings In The 15th Inning” OR “Jones Pitches Brilliant Game, Leaves 7th Inning”.
So, if I use “Jones Pitches Brilliant Game, Leaves 7th Inning” as the headline for the article, that headline will appear on the list pages for both categories. This is fine when it appears on the list page for the “Pitching Duel” Category. But this is not fine when it appears on the list page for the “Extra Innings” Category. It looks weird. It doesn’t relate. It would of course be better and make more sense to the public site’s end user if the headline for this article when it appears on the list page for the “Extra Innings” Category was a different headline, such as “Giants Win In Extra Innings In The 15th Inning”.
I’ve wracked my brain on this. I was thinking about setting up for the article in CMSB several different headline fields, e.g., headline1, headline2, headline3, etc., and using these to write several different headlines for the article. But I cannot think of how to tie these headlines to what gets outputted when a Category is selected by the end user of the public site.
In very broad conceptual terms, I guess that this needs something that correlates the headline1 etc. to what Category gets selected. This can’t be hard coded and must work dynamically depending on the Category.
I was further thinking in trying to suss this out that I’d also probably need to indicate which Category the headline1 relates to and goes with, and maybe could somehow do this in the headline1 field entry itself when I write the headline, i.e., some code parenthetical (that doesn’t appear to the public user) I put in the headline1 field itself to say what Category the headline goes with, maybe something like:
headline1 field:
<?php ‘category’=9 ?> Jones Pitches Brilliant Game, Leaves 7th Inning
AND
headline2 field:
<?php ‘category’=12 ?> Giants Win In Extra Innings In The 15th Inning
But even if this is possible (to use php code in the field itself) and the right approach for saying what Category the particular headline goes with, I still can’t see what code I’d need in the foreach loop on the list page to tell it that if the selected category is Category num 9, then use the headline1, and likewise if the Category is num 12, then to use in that case the headline2 field.
One thing I thought about and rejected is creating multiple copies of the article, each copy with its own headline and assigned single Category. That would wreck havoc and not be manageable for many reasons, including the fact that there’s going to be hundreds of articles and this would just confuse thing terribly to have multiple copies of the same article.
Another thing I thought about and rejected is to write the single headline for the article that covers all these game aspects of the game, but that would result in headlines I don’t really want and that’d be too long, because a game might have 5 aspects and fall into 5 Categories.
So, any ideas on how to have different headlines for the same article appear on list pages depending on the Category shown by the list page?
Thanks,
David
I want to make the headlines that appear for the articles, both in the list pages and on the article page itself, change depending on the CMSB Category.
Here’s what I mean specifically:
The articles are summaries of baseball games. I’ve set things up in CMSB so that the articles get “tagged” by assigning them to one or more of several CMSB Categories I’ve set up in CMSB for what type of game it was. (I use a multi-select list in CMSB Admin for this.) For example the CMSB Categories and Sub-Categories for game types I’ve set up in CMSB Admin are:
-Game Summaries:
—Pitching Duels
—Slug Fests
—Extra Innings
[note: my system actually has dozens of these subcategories, so there’s lots of them]
So, if a game was only a Pitching Duel, the article for it gets assigned to that CMSB Category. When a public end user of the site selects that Category from the menu on the public page, the article for this game appears in the article list (along with all the other articles also tagged with this CMSB Category).
And, if a game was both a Pitching Duel and an Extra Innings game also, the article for it gets assigned to both of those CMSB Categories. This way, that article appears on the list page if either CMSB Category — Pitching Duel or Extra Innings — is selected by the public end user viewing the site.
I’ve got the foregoing set up and running fine.
BUT here’s the problem I’m trying to solve now:
Using the last example above, i.e., an article that’s assigned to two or more CMSB Categories (such as one that’s assigned to both, e.g., the Pitching Duel and the Extra Innings CMSB Categories), will appear on on both these list pages with the same headline. That’s a problem. Here’s an example why.
If an article about a game was both a Pitching Duel and also an Extra Innings type game, the single headline for that article I write when creating the article in CMSB Admin (there is a filed named ‘headline’) might just be about only one of these aspects — e.g., “Giants Win In Extra Innings In The 15th Inning” OR “Jones Pitches Brilliant Game, Leaves 7th Inning”.
So, if I use “Jones Pitches Brilliant Game, Leaves 7th Inning” as the headline for the article, that headline will appear on the list pages for both categories. This is fine when it appears on the list page for the “Pitching Duel” Category. But this is not fine when it appears on the list page for the “Extra Innings” Category. It looks weird. It doesn’t relate. It would of course be better and make more sense to the public site’s end user if the headline for this article when it appears on the list page for the “Extra Innings” Category was a different headline, such as “Giants Win In Extra Innings In The 15th Inning”.
I’ve wracked my brain on this. I was thinking about setting up for the article in CMSB several different headline fields, e.g., headline1, headline2, headline3, etc., and using these to write several different headlines for the article. But I cannot think of how to tie these headlines to what gets outputted when a Category is selected by the end user of the public site.
In very broad conceptual terms, I guess that this needs something that correlates the headline1 etc. to what Category gets selected. This can’t be hard coded and must work dynamically depending on the Category.
I was further thinking in trying to suss this out that I’d also probably need to indicate which Category the headline1 relates to and goes with, and maybe could somehow do this in the headline1 field entry itself when I write the headline, i.e., some code parenthetical (that doesn’t appear to the public user) I put in the headline1 field itself to say what Category the headline goes with, maybe something like:
headline1 field:
<?php ‘category’=9 ?> Jones Pitches Brilliant Game, Leaves 7th Inning
AND
headline2 field:
<?php ‘category’=12 ?> Giants Win In Extra Innings In The 15th Inning
But even if this is possible (to use php code in the field itself) and the right approach for saying what Category the particular headline goes with, I still can’t see what code I’d need in the foreach loop on the list page to tell it that if the selected category is Category num 9, then use the headline1, and likewise if the Category is num 12, then to use in that case the headline2 field.
One thing I thought about and rejected is creating multiple copies of the article, each copy with its own headline and assigned single Category. That would wreck havoc and not be manageable for many reasons, including the fact that there’s going to be hundreds of articles and this would just confuse thing terribly to have multiple copies of the same article.
Another thing I thought about and rejected is to write the single headline for the article that covers all these game aspects of the game, but that would result in headlines I don’t really want and that’d be too long, because a game might have 5 aspects and fall into 5 Categories.
So, any ideas on how to have different headlines for the same article appear on list pages depending on the Category shown by the list page?
Thanks,
David
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:
Hope this helps get you started.
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/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/