show only articles for an issue of a selected newsletter

11 posts by 3 authors in: Forums > CMS Builder
Last Post: February 10, 2010   (RSS)

By craig_bcd - January 19, 2010

Hey guys you have always been so helpful in the past and I have hit a wall.

Here is what I want to do:

My client creates newsletters and newsletters have articles, simple enough. They do it through constant contact and want to have summaries in constant contact then link back to the site for the full article. The articles will also be on their site in complete summary, article form which is what I am working on here.

They want people to select the newsletter they want on a page and then to display title and summary of only those articles in that issue then link to the whole article with a subnav of titles of all the possible articles for that newsletter.

I can do the articles for an issue with title and summary then view the whole article with a subnav - those mechanics I largely understand.

I think, in order to display only the the articles for a specific issue I need to just change the where clause on the page to reflect where year = x and where issue = y (year and issue are stored as lists so I know the values).

My problem is how do I get the value of what the user has selected (year and issue of the newsletter) to impact the where clause such that only those articles show up.

I have tried appending it to the URL and parsing the URL, I have tried storing it in a cookie I tried storing it in a session variable but none of these has worked for me.

Here is the code that I have and frankly I am not sure that is even right any more.

Here is the first page where you select the newsletter you want to read:

Here is a link to the select page:

Then, only the december/january works since that is what is programmed into the where clause of the linked page, here:

I have not built the final page where they link from the article summary but the idea is that the view_newsletter page looks and works much link this news page on their website (except of course it lists only the articles for the specific issue they selected rather than all articles like the news does).

I am open to any way to do this, certainly the path I am on now is not working...

thanks for your help

Re: [craighodges] show only articles for an issue of a selected newsletter

By Chris - January 19, 2010

Hi craighodges,

Can you please post (as an attachment is best) the complete PHP source code for both your new.newsletter.php and view_newsletter.php pages?
All the best,

Re: [chris] show only articles for an issue of a selected newsletter

By craig_bcd - January 19, 2010

Chris -

Absolutely! - thank you. The headercode, homelink, content_top, content_bottom, nav_top, and nav_bottom. are all common files for both view_newsletter and new.newsletter. This must be itteration 10 or 15 by now so the code is not that clean.

thanks again


Re: [craig_bcd] show only articles for an issue of a selected newsletter

By Chris - January 20, 2010

Hi craighodges,

You can't use #anchor-links to pass information, because the browser doesn't send the #anchor part of the link to the server. You'll need to use ?query=strings for this kind of thing. I would avoid session variables for something like this.

Am I correct in assuming that wnw_intronewsletter is a Single Record section that you'll be using everywhere on your site? You'll want to get rid of the where clause and disable searching: (new code in red)

list($wnw_intronewsletterRecords, $wnw_intronewsletterMetaData) = getRecords(array(
'tableName' => 'wnw_intronewsletter',
'where' => whereRecordNumberInUrl(1),
'allowSearch' => '0',
'loadUploads' => '0',
'limit' => '1',
$wnw_intronewsletterRecord = @$wnw_intronewsletterRecords[0]; // get first record

You may also consider moving that code into an include to avoid repeating it on several pages. If you are, in fact, including it everywhere, you can move your require_once "/usr/www/users/thephila/cmsAdmin/lib/viewer_functions.php"; into that include too. :)

Now that we've disabled searching on the other getRecords calls on your pages, we can safely start using the query string to search. Instead of hardcoding new.newsletter.php's new_nwsltr_hm getRecords() to filter where category=1, you can remove that where line and direct users to new.newsletter.php?category=1. I'm not sure if you really want to do this or if that page should be hardcoded, but we'll use the same functionality in a moment to display the correct articles in view_newsletter.php.

In new.newsletter.php, change these lines:

<?php $_SESSION['newsletter_issue'] = $record['newsletter_issue'];?>
<li class="li_newsltr"><i><?php echo $record['title'] ?></i> - <a href="view_newsletter.php#<?php echo $record['newsletter_issue']?>"><?php echo $nltrIssue; ?></a><?php echo $_SESSION['newsletter_issue'];?> </li>


<li class="li_newsltr"><i><?php echo $record['title'] ?></i> - <a href="view_newsletter.php?newsletter_issue=<?php echo $record['newsletter_issue']?>&category=<?php echo $record['category']?>"><?php echo $nltrIssue; ?></a><?php echo $record['newsletter_issue'];?> </li>

In view_newsletter.php, remove these lines:

list($new_newsletterRecords, $new_newsletterMetaData) = getRecords(array(
'tableName' => 'new_newsletter',
'loadUploads' => '0',
'allowSearch' => '0',
'where' => 'category=1',
'where' => 'newsletter_issue="04dec_jan"',

With allowSearch enabled, view_newsletter.php will automatically do its filtering using the query string (e.g. ?newsletter_issue=04dec_jan&category=1).

Finally, you'll want to include a link to the article's detail page: (new code in red)

Article title: <a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>

Does that help? Please let me know if you have any questions.
All the best,

Re: [craig_bcd] show only articles for an issue of a selected newsletter

By Chris - January 27, 2010

Hi Craig,

PHP includes don't support query strings (i.e. ?like=this) and you can't parameterize PHP code like this.

Why do you want to use includes like this?

You might find it simpler to include the header and footer of the page and leave the "content" part of the page in the page that's being requested.
All the best,

Re: [chris] show only articles for an issue of a selected newsletter

By craig_bcd - January 27, 2010

Well - that certainly explains why it does not work. What I want to do is have subnav on that page of all the articles in a particular issue so that you can easily swap between the articles in a particular newsletter.

Do you have any ideas on how I can do that?

Re: [chris] show only articles for an issue of a selected newsletter

By craig_bcd - January 28, 2010

hey Chris -

Never mind on this one - I ended up writing it out and back in to session cookies and it works beautifully. Thanks for your help on the other, could not have done it without you.



Re: [craig_bcd] show only articles for an issue of a selected newsletter

By gkornbluth - January 28, 2010


An interesting approach. Could you share what you've done so that we can learn from it also?


The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at:

Re: [gkornbluth] show only articles for an issue of a selected newsletter

By craig_bcd - January 29, 2010

Sure Jerry - no problem. Hope it helps others.

As you will note by reading above we are posting newsletters on to the website - on the opening page we select the newsletter, year and issue, then pass those variables pulling up the article titles, summary and link for each article in that issue. On this page, in the foreach loop we essentially copy the link information to a session variables array. When you click on the link to read the whole article the we recall the session variables to create a subnav on that page.

So we open a session at the top:
<? session_start(); unset($_SESSION['values']); ?>

in the foreach loop we copy the link information to session variables:
<?php foreach ($new_newsletterRecords as $record): ?>
<h3><?php echo $record['title'] ?><br/><span class="homenewsdate"><?php echo $record['author'] ?></span></h3>
<p><?php echo $record['summary'] ?> - <a href="<?php $_SESSION['values'][] = $record['_link']; echo $record['_link']; ?>"><?php echo $record['link_text'] ?></a></p>
<p class="sep"></p>
<?php endforeach; ?>

Then when you click on an article link to view the whole article, in the php file that creates the subnav for the page, we read the array back and create the subnav.

<?php foreach ($new_newsletterRecords as $record): ?>
<?php $pg_link = $record['_link']; ?>
<? if(in_array($record['_link'],$_SESSION['values'])) { ?>
<?php $compare = strpos($pg_name,$pg_link); ?>
<?php if ($compare === false ):?>
<?php $link_class = "pad"; ?>
<li><a href="<?php echo $record['_link']; ?>" class="<?php echo $link_class; ?>"><?php echo $record['title']; ?></a></li>
<?php else: ?>
<?php $link_class = "idselect"; ?>
<li class="<?php echo $link_class; ?>"><?php echo $record['title']; ?></li>
<?php endif; ?>
<? } ?>
<?php endforeach; ?>

That is it. Let me know if any of it needs further explanation.