1 article AND headlines on homepage?

Hi.. i can't figure this out and not sure if it's actually possible.

On my index page i'm trying to have just 1 news post (which is truncated with a readmore link..) and then a list of headlines with dates on the right.

I guess i just use the news loop for the headline list - how do i limit that list to say..the 5 most recent?

And then for the news article.. how do i just display the latest one?

Remember this is all on the same page. I tried using 2 news loops and they conflicted.

Thanks for any help!!

Comments

  • acrylian Administrator, Developer
    Two loops are not possible but for this case there are the `getLatestNews()/printLatestNews()` functions. That would be the easiest. Please see the documentation for more info.
  • Thansk Acrylian...

    I've looked at the template-functions page and have found getLatestNews().

    I don't understand how i impliment it though. I tried this but it just gave me a bunch of syntax errors.

    <?php array getLatestNews( [int $number = 5], [string $option = 'none'], [string $category = ''] ) ?>
  • uhh.. nevermind, i understand it now.

    However, is there a way to get it to only display news? It seems to be displaying both news and album updates. I figure i could just define a category to keep it to news, but i need multiple news categories so that won't work. Is there a way to define a type of news?

    this is my line so far:

    <?php printLatestNews($number='1'); ?>
  • sorry i'm an idiot. dunno how i missed that $option string.
  • acrylian Administrator, Developer
    Btw you don't need to write `?php printLatestNews($number='1'); ?>`but `?php printLatestNews(1); ?>`. I suggest taking a look here maybe: http://www.zenphoto.org/2008/04/how-to-read-the-zenphoto-functions-guide/
  • ok here's something i can't figure out..

    Now i've got my line:

    <?php printLatestNews($number='1', $option='none'); ?>

    How do i style the individual items that make up that post? So like, not have it in a UL... style the link header.. etc.

    Is it actually possible without hardcoding it into template-functions.php?
  • acrylian Administrator, Developer
    Several possibilites:
    1) There are css classes attached you can style directly.
    2) Use the `getLatestNews()` to write your own custom output function (basically all functions have a get equivalent for that reason). You will of course need php knowledge to manage that.
  • so it's not as simple as doing something like this?

    <?php getLatestNews(1,none);
    <h2> printNewsTitleLink(); </h2><span>printNewsDate(); </span>
    <p> printNewsContent(); printNewsReadMoreLink(); </p>
    ?>
  • this seems to work. is this correct?

    <?php

    $latest = getLatestNews(1,none);

    foreach($latest as $item) {

    $title = htmlspecialchars(get_language_string($item['title']));
    $link = getNewsURL($item['titlelink']);
    $content = strip_tags(get_language_string($item['content']));

    echo "<h3>".htmlspecialchars($title)."</h3>\n";
    echo "<p>".htmlspecialchars($content)."</p>\n";

    }?>
  • acrylian Administrator, Developer
    Yep, that is the right way. (btw none does not need to be set since it is the default values if nothing is entered. If you enter anything else it should be in quotes)
  • excellent. thanks so much for the help.
Sign In or Register to comment.