[resolved] [Plugin: Post-Page-Associator] Get Associated Posts inside Themes (6 posts)

  1. Wiki Chaves
    Posted 5 years ago #


    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



  2. Dennis Hoppe
    Posted 5 years ago #

    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
        // Now the current associated post is in $post and you can use the template tags
        // Now the easy part
        Echo '<div>';
          Echo '<h3>';
          Echo '</h3>';
          Echo '<p>';
          Echo '</p>';
        Echo '</div>';
    Else {
      // No posts :(
      Echo 'Sorry, no posts are attached to the page '.get_the_title($page_id);
  3. Wiki Chaves
    Posted 5 years ago #

    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


  4. Dennis Hoppe
    Posted 5 years ago #

    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;'));
  5. Wiki Chaves
    Posted 5 years ago #

    Thanks Denis :)

  6. steveyoung
    Posted 5 years ago #


    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.

Topic Closed

This topic has been closed to new replies.

About this Topic