Two sections on same page referencing same section editor

14 posts by 5 authors in: Forums > CMS Builder
Last Post: May 25, 2011   (RSS)

By (Deleted User) - March 3, 2010

I have talked to Donna about this and she suggested a PHP include. Seemed like a smart idea but I have been unable to get it working.

The desire is this:

ON every page of the site have a list of "recent blog posts" including the blogs list page and detail page. An example can be found here:

http://www.gourmetguy.biz/index3.php

What I find happening is on the blog detail page because I reference the same code twice instead of listing the latest 5 posts it would only list the single post for that page. An example can be found here:

http://www.gourmetguy.biz/chef_blog_detail.php?Why-I-Promote-Seasonal-Foods-1

Donna suggested an include which I put on the listing page as a test under the already existing code. An example of which can be found here:

http://www.gourmetguy.biz/chef_blog_list.php

My question is...when referencing the same viewer code on hte same page how do I get it to display one item for the blog page detail and 5 items for the latest posts.

Apologies for my newbie status question. I have attached the code for the detail and listing page for reference.

Re: [cohagan] Two sections on same page referencing same section editor

By Dave - March 4, 2010

Hi cohagan,

What's happening is the viewers are overwriting each others variables. You can name the variables whatever you want. Try renaming one set of variables.

For example, on the detail page:
list($blogDetailRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$blogRecord = @$blogDetailRecords[0]; // get first record


Or for the include file you could rename it as:
$latestBlogRecords

For the include error you're getting "Warning: Cannot modify header information", try removing this line from your include:
<?php header('Content-type: text/html; charset=utf-8'); ?>

Since the include is being included in the middle of an existing html page it doesn't need to send a header to tell the browser what kind of content or charset is coming. (And if fact, can't since the headers are always sent in advance of the HTML).

Hope that helps! Let me know if there are any more issues or you have any questions about any of that. :)
Dave Edis - Senior Developer
interactivetools.com

Re: [cohagan] Two sections on same page referencing same section editor

By (Deleted User) - March 5, 2010

Dave I have removed the HTML header. That worked perfectly. I have changed the name within the include and that also worked perfectly.

The site behavior is still not right however.

The latest posts section should list 5 most current posts which have the "go live" field set to yes.

Instead, on

http://www.gourmetguy.biz/chef_blog_list.php

it lists 4 of the latest because one of the latest does not have go live selected. In retrospect this makes sense since I have placed a limit on the amount of total records being read to 5.

So, if I raise the limit, I will get too many records. If I remove the "check to see if this is live" part it will show "not ready for primetime" blog entries.

I have attached the offending files. Any hint at what needs to be done will be received gratefully and enthusiastically. You can teach me to fish rather than fish for me if that saves time :)

Re: [cohagan] Two sections on same page referencing same section editor

By Dave - March 8, 2010

Hi Chris,

Try adding these lines to getRecords() at the top of test.php:

list($latestblogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'perPage' => '5',
'orderBy' => 'date DESC, title',
'where' => " live = 1 ",
'allowSearch' => false,

'loadUploads' => '0',
));


And removing these lines below:

<?php foreach ($latestblogRecords as $record): ?>
<?php if ($record['live']): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php endif ?>
<?php endforeach ?>


This will load 5 records from the database that are live, rather than 5 recent records and show only the live ones (leaving you with 0-5 visible records).

And the 'allowSearch' => false, isn't required but is a good idea for includes so that they ignore anything in the url that might trigger that automatic search engine features: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

For example, you might have a search results page with a "latest 5 records" include. You'd want the search results to be filtered based on the search, but not the results in the include. That's what 'allowSearch' => false, does.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Two sections on same page referencing same section editor

By (Deleted User) - March 8, 2010

Very nice elegant solution. I am guessing I will need to learn more about "where" and its uses with your software.

Unfortunately, it seems to load only 4 of the 6 possible "live" blog posts rather than 5. It lists the next two on the following page whereas it should list 5 and 1?

http://www.gourmetguy.biz/chef_blog_list.php

Any idea why?

Re: [cohagan] Two sections on same page referencing same section editor

By Theo - March 8, 2010 - edited: March 8, 2010

I think you still have some conflicting viewer code. Make sure that ALL your variable names for your sidebar are different from your main content.

So if you're using "$latestblogRecords" in your sidebar, and "foreach ($latestblogRecords as $record)" to create your record list, in your page you could use "$chefblogRecords" and "foreach ($chefblogRecords as $chefblogRecord)".

Often using the variable $record is what gets you into trouble.
Theo Wiersma

Re: [Theo] Two sections on same page referencing same section editor

By Theo - March 8, 2010

(The reason I'm pretty sure this is the problem: when you go to page 2, your headlines sidebar changes as well...)
Theo Wiersma

Re: [cohagan] Two sections on same page referencing same section editor

By Dave - March 8, 2010

Try adding this to force it to always show the first page of results and ignore the page=# in the url:

'pageNum' => 1,

The 'where' actually part of a MySQL query. CMSB is pretty lightweight, instead of teaching you a made-up system much of this is straight PHP and MySQL that you are learning! Which is great because that means you'll be able to use that knowledge in many other places as well.

Let me know if there are any remaining issues after you hard-code the pageNum.
Dave Edis - Senior Developer
interactivetools.com

Re: [Theo] Two sections on same page referencing same section editor

By (Deleted User) - March 8, 2010

OK each section has a unique variable name now. Behavior is the same.

It can't be using $record as I did a search and made sure each section used a different name.