Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Select latest article and display differently?

Status
Not open for further replies.
Joined
Jun 1, 2010
Posts
552
Reaction score
2
At the moment I use the code below to display all articles from my database in small, rectangular boxes with a small thumbnail on one side. However, I would like to display the latest article as a large picture with the other info underneath. I thought it would be (and probably is to non-noobs) simple to do but I can't workout how to grab the latest article. I can do everything styling wise, it's just getting the latest article. The articles all have an incremental id. Any help would be much appreciated!

<ul id="headlines">

<?php foreach ( $results['articles'] as $article ) { ?>

<li>

<?php if ( $imagePath = $article->getImagePath( IMG_TYPE_THUMB ) ) { ?>

<a href=".?action=viewArticle&amp;articleId=<?php echo $article->id?>"><img class="articleImageThumb" src="<?php echo $imagePath?>" alt="Article Thumbnail" /></a>

<div id="shortsummary">

<h2><a href=".?action=viewArticle&amp;articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a>
<span class="pubDate"><?php echo date('j F', $article->publicationDate)?></span>
</h2>

<p class="summary">

<?php } ?>
<?php echo htmlspecialchars( $article->summary )?>
</p></div><?php } ?>

</li>

</ul>
 
Could set a count such $imcount =1 before the start off your loop then. before the end of the loop $imcount++

Then around your image display a different class with an if statement when $imcount is >2
 
Selecting the latest article would be a mysql thing, a quick and easy way is something like

SELECT id, text, whatevr FROM `articles` order by id desc limit 1;

that would select just the last one, changing 1 to 5 would select the last 5 in reverse order.
 
I understand what both of you are saying, but could you give an example how I would integrate either answer with what I already have (can't emphasize my noobness enough)? Thanks
 
Was on the tablet last night so couldn't put it in your code this should work

Code:
<ul id="headlines">
<?php 
$imcount = 1;
foreach ( $results['articles'] as $article ) { ?>
<li>
<?php if ( $imagePath = $article->getImagePath( IMG_TYPE_THUMB ) ) { ?>
<a href=".?action=viewArticle&amp;articleId=<?php echo $article->id?>"><img class="<?php if ($imcount < 2) { echo "articleImageThumbLarge";} else {  echo "articleImageThumb"; } ?>" src="<?php echo $imagePath?>" alt="Article Thumbnail" /></a> 
<div id="shortsummary">
<h2><a href=".?action=viewArticle&amp;articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a>
<span class="pubDate"><?php echo date('j F', $article->publicationDate)?></span>
</h2>
<p class="summary">
<?php } ?>
<?php echo htmlspecialchars( $article->summary )?>
</p></div>
<?php 
$imcount++;
} ?>
</li>

In your css create an articleImageThumbLarge class and apply the styling you want to it
 
You haven't posted the SQL part to implement it, but look for something which looks like the select statement I posted, and should be easy to modify that :)
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom