Article coding

13 posts by 3 authors in: Forums > CMS Builder
Last Post: July 20, 2010   (RSS)

By design9 - July 13, 2010

Hello,
I have some article coding on my pages that works fine but I need to adjust one area now and need some help in the right direction.

I have attached my page with the coding below and I have a feature article section that displays the article in that section based on the user inputting the article id number in the backend. Then I have an all articles section that pulls in the most recent 25 articles for that topic.

I need to now adjust or change the coding in the feature article section so it can auto-feed 3 articles based on the most recent publish date. So, I no longer need it to input the article in that area based on the id number like it is now. I need it to work similar to the all articles section but the only difference is I need to only pull 3 articles and I need to base it on the publish date. I still need it to pull the 3 articles for that topic like the all articles section does.

The feature article area coding that is currently on the page is on lines 40-62 and 263 - 296 if you need to look at that.

Thank you,
April
Attachments:

index_024.php 48K

Re: [apdance9] Article coding

By gkornbluth - July 13, 2010

Hi April,

You probably tried this already, and I'm not sure if it will work, but what happens if you insert 'limit' => '3', in the featured article call $articleRecords = array();
if ($preg_breastfeedingRecord['featured_article_1']) {
list($featuredarticlesoneRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => 'num IN (' . $preg_breastfeedingRecord['featured_article_1'] . ')',
'limit' => '3',
));


Best,

Jerry Kornblutbh
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] Article coding

By design9 - July 13, 2010

Thanks but that will not work because I actually need it to auto feed. I don't want the user to have to put the id number in the backend. We are trying to limit the amount of work the user has to update in backend. I want it to automatically feed in the 3 most recent articles based on the publish date.

April

Re: [apdance9] Article coding

By gkornbluth - July 13, 2010 - edited: July 13, 2010

Hi April,

I'm probably missing something important, but how about sorting by publish date first, then limiting the articles to 3 in the viewer?

'limit' => '3',
'orderBy' => 'date',

(change "date" to your publish date field name

I didn't look too closely at the viewer code you have, but that, in theory should display the 3 newest articles.

Best,

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] Article coding

By design9 - July 13, 2010

The issue is that I already have coding on the page that pulls in all articles for the topic that I want to keep that is similar to what you are saying. The feature coding that I need has to be slightly different and that is where I am having trouble. Chris helped me originally when writing some of this special coding so I think I need Chris or Jason to help with this.

Thanks!

April

Re: [apdance9] Article coding

By Jason - July 13, 2010

Hi April,

I've taken a look at what you have so far, and I think Jerry may have been close. What we want to be able to do is to select the first 3 articles (based on the date they were created) for a given topic (ie, category). Is this correct?

If this is correct, we can try something like this. In this example, we're using the category "Breastfeeding", which seems to be the category being used in the page you sent:

list($featuredarticlesoneRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => "category LIKE '%\tBreastfeeding\t%'",
'orderBy' => 'createdDate desc',
'limit' => '3',
));


This should return the records that we're looking for. Give this a try and let me know if we're close.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Article coding

By design9 - July 13, 2010

Jason, that works perfectly. I guess I thought it was going to be more complicated than this.

Also, here is the page with the coding...what would be the easiest way to get them to each go back into seperate div tags or 3 columns. I know I can do the php max column code using a table but not sure if there would be an easier way.

Here is the page now (I made 1 div tag here):

http://www.charlotteparent.com/test/pregnancy/breastfeeding/indextest.php

Here is a sample of how I want them to feed and look:

http://www.charlotteparent.com/test/pregnancy/index.php

Thanks to you and Jerry for your help!

April

Re: [apdance9] Article coding

By Jason - July 13, 2010

Hi April,

Glad that's working out for you.

We can do a 3 column display pretty easily using the <div>'s you were using on the test page. It's best to have a counter variable since even though we know we'll never have more than 3 articles, we don't know if we'll have less than three. I would suggest something like this:


<?php $count=1;?>

<?php foreach($featuredarticlesoneRecords as $article):?>
<?php if($count>3){$count=1;} ?>
<div class="facolumn<?php echo $count++;?>">
*** OUTPUT ARTICLE INFORMATION HERE ***
</div>

<?php endforeach ?>


Give that a try and let me know if that works for you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Article coding

By design9 - July 16, 2010

Jason,
I am having trouble with this. Do I want to use 3 different div tags or one?
Also, I am thinking my coding is not correct.

Here is my code:

<?php $count=1;?>

<?php foreach($featuredarticlesoneRecords as $record):?>
<?php if($count>3){$count=1;} ?>
<div id="facolumn4<?php echo $count++;?>">
<?php foreach ($record['photo'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" style="border: solid 1px #4f4f4f;" /><br/>
<?php endif ?>
<?php endforeach ?>
<a href="<?php echo $record['_link'] ?>"><span class="articlehead"><?php echo $record['title'] ?></span></a><br>
<span class="articlebody"><?php echo $record['summary'] ?>
</span>
</div><?php endforeach; ?>

Here is the test page url again:
http://www.charlotteparent.com/test/pregnancy/breastfeeding/indextest.php

Can you help me figure out what I am doing wrong?

Thanks!
April