Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a function in functions.php that includes the next_post_link() and previous_post_link() without success. It returns empty. My guess is that these don't use the post ID... So what would be the best way to do that so I can store them values in $next_link and $previous_link in the following code?

<?php
function get_all_images($post_id=0, $size='poster', $attributes='') {
    $post_id = $_POST['post_id'];
    if ($post_id<1) $postid = get_the_ID();
    if ($images = get_children(array(
        'post_parent' => $post_id,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby' => 'menu_order',
        'post_mime_type' => 'image',)))
        $title = get_the_title($post_id);
        $next_link = next_post_link($post_id);
        $previous_link = previous_post_link($post_id);
        $response = '<div class="post-control left">'.$next_link.'</div><div class="post-control right">'.$previous_link.'</div><div class="post-titles titles">'.$title.'<span class="ajust-icon pull-right"><a href="/blog" class="backtoblog"><i class="icon-remove icon-white"></i></a></span></div>';
        foreach($images as $image) {
            $attachment=wp_get_attachment_image_src($image->ID, $size);
            $tranparent=get_template_directory_uri();
            $response .= '<img src="'.$tranparent.'/images/transparent.gif" data-original="'.$attachment[0].'" alt="" class="imarge" />';
        }
    $get_post = get_post($post_id);
    $get_content = $get_post -> post_content;
    $content = apply_filters('the_content', $get_content);
    $content = str_replace(']]>', ']]&gt;', $content);
    die(json_encode($response.$content));
}?>
share|improve this question
    
    
@Michael did you read the question? Where does it explain in the link you provided the way to call these in functions.php ? –  Gab Sep 26 '12 at 20:34
    
it does not - it explains that the post ID is not a valid parameter, and that the function has to be used in the loop. I added the link as a comment why I downvoted your topic, not as an answer. –  Michael Sep 26 '12 at 20:58
    
@Michael I said in my question I knew it wasn't using ID as parameter... So the question was what to do then? I don't understand why you downvoted my question! Just to make sure I don't get any help? :-/ Not helping... at all. –  Gab Sep 26 '12 at 21:03
add comment

1 Answer 1

up vote 0 down vote accepted
<?php
function get_all_images($post_id=0, $size='poster', $attributes='') {
    global $post;
    setup_postdata($post);
    $post_id = $_POST['post_id'];
    if ($post_id<1) $postid = get_the_ID();
    $post = get_post($post_id);
    $get_content = $post -> post_content;
    $content = apply_filters('the_content', $get_content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $title = get_the_title($post);
    $previous_post = get_previous_post();
    $next_post = get_next_post();
    $previous_link_url = get_permalink(get_previous_post(false,'',true));
    $next_link_url = get_permalink(get_next_post(false,'',false));
    if (!empty( $previous_post )) $previous_link = '<div class="post-control right"><a href="'.$previous_link_url.'" rel="prev">&rsaquo;</a></div>';
    if (!empty( $next_post )) $next_link = '<div class="post-control left"><a href="'.$next_link_url.'" rel="next">&lsaquo;</a></div>';
    if ($images = get_children(array(
        'post_parent' => $post_id,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby' => 'menu_order',
        'post_mime_type' => 'image',))) 
        $response = $previous_link.$next_link.'<div class="post-titles titles">'.$title.'<span class="ajust-icon pull-right"><a href="/blog" class="backtoblog"><i class="icon-remove icon-white"></i></a></span></div>';
        foreach($images as $image) {
            $attachment=wp_get_attachment_image_src($image->ID, $size);
            $tranparent=get_template_directory_uri();
            $response .= '<img src="'.$tranparent.'/images/transparent.gif" data-original="'.$attachment[0].'" alt="" class="imarge" />';
        }
    die(json_encode($response.$content));
}?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.