Simple Array Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daebat
Forum Commoner
Posts: 47
Joined: Mon May 11, 2009 10:16 am

Simple Array Question

Post by daebat »

I'm just installed Yet Another Featured Posts Plugin and it is working just fine but only outputting the title and text for my post. I have a featured image and it claims to have the functionality to do so but I can't figure out the call to the data. Here is what is provided in the documentation:

http://dev.jonraasch.com/yafpp/docs

For advanced users, YAFPP offers some useful output options which can be passed to the get_featured_posts() function like so:

<?php get_featured_posts(array( 'method' => 'return')); ?>

In this example we are setting YAFPP to return the formatted list of featured posts, as opposed to echoing it out like it does by default.

Additionally you can pass 'arr' to get YAFPP to return an array of data for the featured posts. The format for this array is a list of the posts, each of which contain these keys:

<?php array( 'id' => '', // id of the post 'title' => '', // title of the post 'excerpt' => '', // excerpt of the post 'url' => '', // the post permalink 'image' => '', // an array of data for a YAPB image, if it exists 'author' => '', // the post's author); ?>()


Currently my code is like this:

<?php get_featured_posts(array (image, title, excerpt); ?>

Thanks for the help!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple Array Question

Post by pickle »

You're not understanding how the function works. It accepts an array, but it looks like you can either set it to output or return. You need to assign the return value to a variable, then do something with that variable:

Code: Select all

<?php
  $featured_posts = get_featured_posts(array('method'=>'return'));
  //$featured_posts is now an array of arrays, just like you described above
  foreach($featured_posts as $post)
  {
    $post['title']//the title of the current post
    $post['image']//an array containing featured image data.
  }
?>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply