I want to get the IDs of the 2 previous and 2 next articles in a certain category to show them as a "related videos" playlist. I know that there are the functions previous_post_link and next_post_link, which would do the job for me, but I want more than just 1 previous and 1 next link.

Imagine the following scenario:


Post #001
Post #002
Post #003
Post #004
Post #005
Post #006


On Post #001 I want to display #002 and #003.
On Post #003 I want to display #001, #002, #004 and #005.

$post_id = $post-&gt;ID; // current post id

$args = array('category' =&gt; $mycat, 'numberposts' =&gt; 200);
$posts = get_posts($args);
// get ids of posts retrieved from get_posts
$ids = array();
foreach ($posts as $thepost) {
    $ids[] += $thepost-&gt;ID;
}
// get and echo previous and next post in the same category
$thisindex = array_search($post-&gt;ID, $ids);
$prevvid = $ids[$thisindex-2];
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
$nexttid = $ids[$thisindex+2];


I adapted and changed this code from the Wordpress Codex.

And now the part that worries me: If I don't add a large number to numberposts, it will of course only fetch the standard amount of posts and therefore my code won't work the way I want it. I probably will never ever have more than 200 videos in one category. Do you think my solution is a bad idea regarding performance? I didn't find a trick elsewhere to show the adjacent posts.

Thanks in advance for any advice!


Question: Eclipse&Maven - The import org.hibernate.boot.cannot be resolved
Answer: It could be because of the broken classpath;

Package explorer &gt; Plug-in tools &gt; Update classpath.


Or your Hibernate jar is not well extracted from the zip file. For controll, from Project Explorer try to expand your Hibernate jar. If you can't expand probably it's corrupted. Try to add jar again.