Support » Plugins and Hacks » [Plugin: Post-Page-Associator] Get Associated Posts inside Themes

  • Resolved Wiki Chaves

    (@wikichaves)


    Hi,

    I’m getting mad trying to get associated Posts inside my Theme and not at the end of the content, neither inside the content.

    Iยดve tried whith

    wp_plugin_associate_posts_and_pages::get_associated_posts ($post_id = Null);{
    }

    but drops me nothing ๐Ÿ™

    Any ideas ?

    I would also like to have different templates to different parts of the theme. I’ve made one temlpate called “associated-posts.php” and works great, but haw can i do to have more than one template ??

    Plugin version: 1.2.5
    WP version: Iยดve tried with 2.9 and 3.0-RC1

    Regards,
    Francisco

    http://wordpress.org/extend/plugins/post-page-association-plugin/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey Francisco,

    i’ve written a small example. I hope this helps. Otherwise ask more specific please.

    // The id of the page we want to know the associated posts
    $page_id = 308; // Just an example on my machine
    
    // Now we have to ask the plugin if there are posts
    If ( wp_plugin_associate_posts_and_pages::has_associated_posts($page_id) ){
      // Ok. There are posts
      $associated_posts_query = wp_plugin_associate_posts_and_pages::get_associated_posts($page_id);
    
      // The result is a WP_Query object
      While ($associated_posts_query->have_posts()){
        // Set the current $post object
        $associated_posts_query->the_post();
    
        // Now the current associated post is in $post and you can use the template tags
    
        // Now the easy part
        Echo '<div>';
    
          Echo '<h3>';
            the_title();
          Echo '</h3>';
    
          Echo '<p>';
            the_excerpt();
          Echo '</p>';
    
        Echo '</div>';
      }
    }
    Else {
      // No posts :(
      Echo 'Sorry, no posts are attached to the page '.get_the_title($page_id);
    }

    Hey , thanks a lot !
    That worked right ๐Ÿ™‚

    I’m still having the same at the botom of the page after the_content.

    Is there any way to remove this without merging with the plugin ?
    I`ve deleted the content inside the file “associated-posts.php”, but maybie there’s a better way

    Thanks,
    Francisco

    In the new version (1.2.7, please update) i’ve added the ‘associated_posts_auto_append‘ filter for this task. ๐Ÿ™‚

    You can use the filter i.e. this way:

    Add_Filter ('associated_posts_auto_append', // Filter name
                'Control_Auto_Append_For_Associated_Posts'); // Function
    Function Control_Auto_Append_For_Associated_Posts(){
      // if you return True, posts will append to the page
      // if you return False, posts will not append to the page
      return False;
    }

    Or if you like it a little bit more smart…

    // Disables auto append feature:
    Add_Filter ('associated_posts_auto_append', Create_Function('','return False;'));

    Thanks Denis ๐Ÿ™‚

    Dennis,

    Where would this (the code in your first response to Francisco) go in the themes file?

    When adding the shortcode nothing shows with our theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Post-Page-Associator] Get Associated Posts inside Themes’ is closed to new replies.