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!
Simple Array Question
Moderator: General Moderators
Re: Simple Array Question
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.