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;'));
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.