Jump to content

Unwanted full body content in Articles page list?


PhotoWebMax
 Share

Recommended Posts

Another roadblock: I am building a new Article/News container page that presents a list of published articles.

The format for each article I am hoping for is simple:

Title: in an <a> anchor tag

Date

Author name

Summary: first 255 characters from the Body content copy

Continue Reading: also in an <a> anchor tag

My Article post template (I have created the Date and authorName Fields) looks like this:

<h3><?=$page->title?></h3>
<div id='articleCopy'>
	 <?=$page->Date?>
	 <?=$page->authorName?>
    <?=$page->body?>
   </div>

For the parent container Articles page I am using some code from a forum post by Ryan in my template:

<?php include('./_head.php'); // include header markup ?>
<div id="content">
	<div id="mainColumn">
	<?php
	// output 'headline' if available, otherwise 'title'
	echo "<h1>" . $page->get('headline|title') . "</h1>";
		 echo $page->body; // output bodycopy 
		?>
		<?php

		// start the news stories list
		echo "<ul>";

		// get the stories for this page
		$stories = $page->children("limit=4, sort=-date"); 

		// note if you set the stories to sort by date descending on the /news/ page
		// in the admin, then you can omit the "sort=-date" above. 

		// cycle through each story and print it in a <li>
		foreach($stories as $story) {
		    echo "
		        <li><a href='{$story->url}'>{$story->title}</a> 
		        <p>date: {$story->date}</p>
		         <p>by: {$story->authorName}</p> 
		        <?php
				// make our own summary from the beginning of the body copy
				// grab the first 255 characters
				$summary = substr($story->body, 0, 255); 

				// truncate it to the last period if possible
				if(($pos = strrpos($summary, ".")) !== false) {
				    $summary = substr($summary, 0, $pos); 
				}
		        </li>
		        ";      
		}

		echo "</ul>";

		// get values for our placemarker headline
		$start = $stories->getStart(); 
		$end = $start + count($stories);  
		$total = $stories->getTotal(); 
		$num = $input->pageNum; 
		$lastNum =  ceil($total / $stories->getLimit());

		// output the placemarker headline
		echo "<h4>Showing $start - $end of $total Article/s | Page $num of $lastNum</h4>"; 

		// output pagination links
		echo $stories->renderPager();
		?>
		</div><!--mainColumn ends-->
		<div id="sideBar">
			<?php include('./_sidebar.php'); // include sideBar markup ?>
			</div><!--sideBar ends-->
	</div><!--content ends-->
		<?php include('./_foot.php'); // include footer markup ?>

At this point the system is working but with two main issues:

1) On the parent container Articles page each article post will output the Summary and the full body copy. I only want the teaser Summary to appear here. The reader should click on the anchor link in the Title name or the "continue reading" link to read the full story.

2) I am getting unwanted output code at the bottom of the Body content that looks like this:

, 0, 255); // truncate it to the last period if possible if(( = strrpos(, )) !== false) { = substr(, 0, ); }

I have been messing around with this but can't seem to break through these issues. Any pointers here?

Thanks!

Link to comment
Share on other sites

Another roadblock: I am building a new Article/News container page that presents a list of published articles.

The format for each article I am hoping for is simple:

Title: in an <a> anchor tag

Date

Author name

Summary: first 255 characters from the Body content copy

Continue Reading: also in an <a> anchor tag

My Article post template (I have created the Date and authorName Fields) looks like this:

<h3><?=$page->title?></h3>
<div id='articleCopy'>
	 <?=$page->Date?>
	 <?=$page->authorName?>
    <?=$page->body?>
   </div>

For the parent container Articles page I am using some code from a forum post by Ryan in my template:

<?php include('./_head.php'); // include header markup ?>
<div id="content">
	<div id="mainColumn">
	<?php
	// output 'headline' if available, otherwise 'title'
	echo "<h1>" . $page->get('headline|title') . "</h1>";
		 echo $page->body; // output bodycopy 
		?>
		<?php

		// start the news stories list
		echo "<ul>";

		// get the stories for this page
		$stories = $page->children("limit=4, sort=-date"); 

		// note if you set the stories to sort by date descending on the /news/ page
		// in the admin, then you can omit the "sort=-date" above. 

		// cycle through each story and print it in a <li>
		foreach($stories as $story) {
		    echo "
		        <li><a href='{$story->url}'>{$story->title}</a> 
		        <p>date: {$story->date}</p>
		         <p>by: {$story->authorName}</p>"; 
				// make our own summary from the beginning of the body copy
				// grab the first 255 characters
				$summary = substr($story->body, 0, 255); 

				// truncate it to the last period if possible
				if(($pos = strrpos($summary, ".")) !== false) {
				    $summary = substr($summary, 0, $pos); 
				}
		   echo "{$summary}</li>";      
		}

		echo "</ul>";

		// get values for our placemarker headline
		$start = $stories->getStart(); 
		$end = $start + count($stories);  
		$total = $stories->getTotal(); 
		$num = $input->pageNum; 
		$lastNum =  ceil($total / $stories->getLimit());

		// output the placemarker headline
		echo "<h4>Showing $start - $end of $total Article/s | Page $num of $lastNum</h4>"; 

		// output pagination links
		echo $stories->renderPager();
		?>
		</div><!--mainColumn ends-->
		<div id="sideBar">
			<?php include('./_sidebar.php'); // include sideBar markup ?>
			</div><!--sideBar ends-->
	</div><!--content ends-->
		<?php include('./_foot.php'); // include footer markup ?>

At this point the system is working but with two main issues:

1) On the parent container Articles page each article post will output the Summary and the full body copy. I only want the teaser Summary to appear here. The reader should click on the anchor link in the Title name or the "continue reading" link to read the full story.

2) I am getting unwanted output code at the bottom of the Body content that looks like this:

, 0, 255); // truncate it to the last period if possible if(( = strrpos(, )) !== false) { = substr(, 0, ); }

I have been messing around with this but can't seem to break through these issues. Any pointers here?

Thanks!

You're missing some quotation there. Take a Look at the altered Sourcecode in your post (the "$summary" part).

Link to comment
Share on other sites

If I look at the source code I see that the opening php tag is getting added to the markup. This throws validation errors as well. 

<?php
				// make our own summary from the beginning of the body copy
				// grab the first 255 characters
				 = substr(<p>There are methods to treat dreaded red marks without undergoing drastic treatment. The treatment is different for everyone and depends on the particulars of your skin.</p>
Link to comment
Share on other sites

So far I am stabbing at adding quotation but I am getting angry red parse errors...

Edit: I think I have it working now. More template housework to do though...

The Articles container page template now looks like this:

<?php include('./_head.php'); // include header markup ?>
<div id="content">
	<div id="mainColumn">
	<?php
	// output 'headline' if available, otherwise 'title'
	echo "<h1>" . $page->get('headline|title') . "</h1>";
		 echo $page->body; // output bodycopy 
		?>
		<?php

		// start the news stories list
		echo "<ul>";

		// get the stories for this page
		$stories = $page->children("limit=4, sort=-date"); 

		// note if you set the stories to sort by date descending on the /news/ page
		// in the admin, then you can omit the "sort=-date" above. 

		// cycle through each story and print it in a <li>
		foreach($stories as $story) {
		    echo "
		        <li><a href='{$story->url}'>{$story->title}</a> 
		        <p>date: {$story->date}</p>
		         <p>by: {$story->authorName}</p>"; 
				// make our own summary from the beginning of the body copy
				// grab the first 255 characters
				$summary = substr($story->body, 0, 255); 

				// truncate it to the last period if possible
				if(($pos = strrpos($summary, ".")) !== false) {
				    $summary = substr($summary, 0, $pos); 
				}
		   echo "{$summary}</li>"; 
		    echo "<p><a href='{$story->url}'>Continue reading...</a></p>";     
		}

		echo "</ul>";

		// get values for our placemarker headline
		$start = $stories->getStart(); 
		$end = $start + count($stories);  
		$total = $stories->getTotal(); 
		$num = $input->pageNum; 
		$lastNum =  ceil($total / $stories->getLimit());

		// output the placemarker headline
		echo "<h4>Showing $start - $end of $total Article/s | Page $num of $lastNum</h4>"; 

		// output pagination links
		echo $stories->renderPager();
		?>
		</div><!--mainColumn ends-->
		<div id="sideBar">
			<?php include('./_sidebar.php'); // include sideBar markup ?>
			</div><!--sideBar ends-->
	</div><!--content ends-->
		<?php include('./_foot.php'); // include footer markup ?>
Edited by PhotoWebMax
Link to comment
Share on other sites

One thing I notice is that you are trying to truncate to a number of characters. The problem with this is that is really doesn't look very nice if you end part way through a word.

Generally, I think it is better to have a separate summary field so that you can tailor make the summary to look good on the site. But if you are going to truncate, then you can work it out on a word count.

So:

<?php

$maxpostlength = 50;

$text = implode(' ',array_slice(str_word_count($page->body,1),0,$maxpostlength));

echo $text;

I can't remember how I put that together now - it was a couple of years ago, but very useful.

You probably ought to also strip out any tags too.

Using that, you can also change the maxpostlength depending on layout and things like that, which can be useful when going responsive. 

  • Like 1
Link to comment
Share on other sites

Joss,

I was thinking the same thing about the summary. The way I have it now is a cool automated system. But the thing I don't like about it is that the viewer lands up reading the same intro content twice: once on the parent container page and then on the individual full length post page itself.

Creating a separate summary Field means there is an extra step for the editor that is producing these articles but the benefit is that the teaser summary can be anything the editor wants it to be...

Link to comment
Share on other sites

It is worth getting an editor to think in this way. On sites like the BBC they may have three or four different intros to an article, depending on whether is is sort list, headline grabber and so on. It makes for a very rich experience for the reader.

Really, systems like Wordpress do not take into account anything approaching a true editorial process and risk dumbing down good news presentation.

Link to comment
Share on other sites

I need to take a fresh look at the BBC site. 

I am a regular visitor to the Guardian site. They just did a major redesign. I have to say I prefer the old design better. The new system features a ton of boxes which adds a lot of extra scrolling on the user...

Link to comment
Share on other sites

To be honest, this is hard work on an editor, but the ideal solution for a news site would be something like:

Title: just used for backroom records. Example:

Man gets eaten by tiger

Main Headline: Used for full article. Example:

Escaped Tiger attacks jogger in park

Sub: Used for full article - optional lead: Example:

20 year old man is badly injured on Hampstead Heath after being savaged by Tiger, the striped domestic cat

Short Listing headline: This is a much shorted headline for things like sidebar listings where you are short of room. Example:

Tiger Eats Man

Short Listing Summary: This is used in the same way and again, needs to be very short. Example:

20 year old thought critical after Hampstead Heath attack

Large Listing Headline: This would be for more of a blog listing idea. Example.

Man attacked and injured in Tiger attack.

Large Listing Teaser: This is much more like the traditional Summary. Though still succinct. Example:

A man has been rushed to St Mary's Hospital and is reported to be in critical condition following an attack on Hampstead Heath. Police are searching for a Bangal tiger that escaped while being transported from London Zoo.

So, all those use various key words in a variety of ways and find fresh ways of leading people to the article without being cut off or having to write the beginning of the article in a strange way. To be honest, I can think of a proper alternative to this that does not compromise the value of the service to the visitor, even though it does exercise the brain. Still, that is why an editor gets called an editor.

And the front of the full article:

A man was rushed to hospital in suspected critical condition after being attacked by a large cat on Hampstead Heath. The unusual striped cat, a crossbreed tortoiseshell Called Tiger, was later comforted by its owner and is now back safely at home and curled up in bed. The man was later released after it was discovered that most of the blood was the remains of his ketchup sandwich which he had been eating when he fell asleep on the park bench.

In a separate incident, Kahn the tiger from London Zoo was recaptured following his escape from his keepers arms. The six week old tiger cub hit the headlines two weeks ago after he fell asleep on the lap of TV wildlife presenter.......

Dont you love working on news?

  • Like 1
Link to comment
Share on other sites

Hmmm, is this the same tiger that is running amuck through the parks in Paris?

In this case this site is for a skin/acne clinic. I like it when basic brochure sites for businesses offer something of value to the site visitor. Even if they do not use the business services directly its nice to have the reader come away from the site with some learning/knowledge/tips they did not know previously. Presenting some well written topical articles is a good option here. 

PS: I love news. I enjoyed a 20-year career as a daily newspaper photographer before my current gig as a freelance commercial/real estate photographer and part time web guy...

Link to comment
Share on other sites

Hmmm, is this the same tiger that is running amuck through the parks in Paris?

Might be......

Even in the corporate environment with products, being able to list and relate to products in different ways that does not always repeat the same formula surely must enrich the site for customers.

Might be good for SEO too, I suppose (I have no evidence for that in any form whatsoever!)

As for photos, though I do a lot of photography and love it, I am a word man first. I work on the principle of:

"If a picture paints a thousand words,,,,,,"

Then its a pity they are not searchable!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...