Thread Starter
Emilie
(@emiliervgmailcom)
Here is the code for the snippets :
$links = siblings();
$previous = '<span class="prev"><a href="%s"><i class="icon-chevron-left icon-2"></i></a></span>';
echo sprintf($previous, $links['before']);
$next = '<span class="next"><a href="%s"><i class="icon-chevron-right icon-2"></i></a></span>';
echo sprintf($next, $links['after']);
And the code in my functions.php :
function siblings($link) {
global $post;
$siblings = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
foreach ($siblings as $key=>$sibling){
if ($post->ID == $sibling->ID){
$ID = $key;
}
}
$closest = array('before'=>get_permalink($siblings[$ID-1]->ID),'after'=>get_permalink($siblings[$ID+1]->ID));
if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }
}
Thread Starter
Emilie
(@emiliervgmailcom)
Hi,
The problem is with your PHP code. The function siblings() requires an argument to be supplied to it ($link). And your snippet does probably not supply that argument when calling the function. And that is actually what the warning message says:
Warning: Missing argument 1 for siblings()
So change your function, to have a default value for that argument, so if no argument is supplied it takes that one, and you shall get rid of the warning.
ie change
function siblings($link) {
to
function siblings($link = '') {
Cheers,
Johan
Thread Starter
Emilie
(@emiliervgmailcom)
That solved it, thank you! 🙂 Great plugin btw, I just couldn’t find a plugin to insert PHP code that wouldn’t break because of the visual editor. Using shortcode did the thing.