Support » Plugins and Hacks » I need widget to display a linked post

  • I have a client who wants complete control over his posts. He wants to display a related post (thumbnail and excerpt) in his sidebar but wants control over what post shows up.

    It seems to me that there must be a way to link posts. In a post’s edit screen you could specify link to this other post. Then a widget could grab that linked post and put it in the sidebar. Ideally, if no post was linked, nothing would show in the sidebar.

    Anyone know of such a tool?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If I were editing a post, and I added another post’s ID in a custom field (i.e. link two posts together), could I write a one-post loop that would pick up that ID and show that post?

    Would the ID would have to be saved to global in some way?



    Forum Moderator

    OK, it seems that I don’t really need a loop in my sidebar. The template tag get_post should do the trick. I’ve come up with the following php that could be a widget. This assumes:
    a) the widget is only on single posts
    b) there is a custom field called ‘linked_post’ and the value is the ID of the other post.

    <?php if ( get_post_meta($post->ID, 'linked_post', true) ) :
    $the_ID = get_post_meta($post->ID, 'linked_post', true);
    $my_linked_post = get_post($the_ID);
    if( $my_linked_post ) {
    echo the_title();
    endif; ?>

    Unfortunately there seem to be errors in my code. Anyone want to try to fix it? [edit: changed get_posts to get_post, no plural]

    Um, I see why that’s not working:
    get_post_meta($post->ID, 'linked_post', true);
    would only work inside the loop. I need to get a post’s custom field value from outside the loop.

    Does anyone know how to get a post’s custom field value from outside the loop?

    i.e. you are on a single-post, you have a sidebar widget, and the widget needs something from the post’s custom field.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I need widget to display a linked post’ is closed to new replies.