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)

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: http://www.tpschool.org/wnw/new.newsletter.php

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

http://www.tpschool.org/wnw/view_newsletter.php

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).

http://www.tpschool.org/wnw/news.php

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,
Chris

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

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

Craig

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>


to:

<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,
Chris

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

Chris - you guys are so helpful, that was perfect, now I just have one more issue.

So the main page is here: http://www.tpschool.org/wnw/new.newsletter.php

It links to the specific newsletter here: http://www.tpschool.org/wnw/view_newsletter.php?category=1&academic_year=2009_2010&newsletter_issue=04dec_jan passing the variables works brilliantly.

Now when you click to "read more" the full article should show up as well as a sub nav box that lists all the articles in that issue. Subnav is done through an include using the following code:
<?php

require_once "/usr/www/users/thephila/cmsAdmin/lib/viewer_functions.php";

list($new_newsletterRecords, $new_newsletterMetaData) = getRecords(array(
'tableName' => 'new_newsletter',
'loadUploads' => '0',
'allowSearch' => '1',
));
$new_newsletterRecord = @$new_newsletterRecords[0]; // get first record

// show error message if no matching record is found
if (!$new_newsletterRecord) {
print "Record not found!";
exit;
}

?>

<table>
<tr>
<td style="width: 300px; vertical-align:top;" >
<table style="width: 100%">
<tr>
<td style="width: 300px; vertical-align:top;" class="subnav_background">
<div id="sub">

<?php $pg_link = ""; ?>
<?php $pg_ref = ""; ?>
<?php $compare = ""; ?>
<?php $link_class = ""; ?>
<?php $pg_name = ( $_SERVER['REQUEST_URI']); ?>

<ul>
<li><a href="http://www.tpschool.org/wnw/new.newsletter.php" class="pad">Back to Newsletters</a></li>
<?php $lastBox = ""; ?>
<?php foreach ($new_newsletterRecords as $record): ?>
<?php $pg_link = $record['_link']; ?>
<?php $compare = strpos($pg_link,$pg_name); ?>
<?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; ?>
</ul>
</div>
</td>


If I pass the parameters outside of the include on the page, it works perfectly pulling the correct articles.
http://www.tpschool.org/wnw/subnltr.php?academic_year=2009_2010&newsletter_issue=04dec_jan

If I try to add the search string as a part of the include with this code:
<?php include($_SERVER['DOCUMENT_ROOT'] .'/wnw/subnltr.php?academic_year=2009_2010&newsletter_issue=04dec_jan');?>

I can do it without the document root variable and still no work. If I do it without the search string on the end, the page works perfectly but I get all articles in the database, not just the ones related to that issue.

If I do it with the search string on the end (I just hard coded it to see if I could get it to work) I get an error message:Warning: include(/usr/www/users/thephila//wnw/subnltr.php?academic_year=2009_2010&newsletter_issue=04dec_jan): failed to open stream: No such file or directory in /usr/www/users/thephila/wnw/new.viewnltr_wnw.php on line 64 Warning: include(): Failed opening '/usr/www/users/thephila//wnw/subnltr.php?academic_year=2009_2010&newsletter_issue=04dec_jan' for inclusion (include_path='/usr/www/users/thephila/cmsAdmin:.:/usr/local/lib/php') in /usr/www/users/thephila/wnw/new.viewnltr_wnw.php on line 64

I uploaded the code for both pages below (subnltr.php creates the sub-nav, new.viewnltr_wnw.php is the page with the article and the subnav - any help is appreciated since now I am not sure how to pull this off.

thanks!

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

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

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.

Thanks

craig

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

Craig,

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

Thanks

Jerry
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: http://www.thecmsbcookbook.com/trial.php

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

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.