Showing Attached Posts on post page
-
Hello guys,
I am having some problem displaying a list of posts preferably with excerpts on a post page.
Now I am using gravity forms to let users submit posts on a post page, what the gravity forms do is, they record the post ID of the post that the form was submitted on. So that new post that has been made by the form has a forum ID of the post that it was submitted from.
What I want to do is display all posts that are attached to a specific post ID in their respective posts.
I’ve gotten some tutorials, here is what I am trying to get… this obviously is with attached images, I just want this to be changed to links to those attached posts possibly having excerpts as well
https://theme.fm/wp-content/uploads/2011/07/post-attachments-plain-600×376.png
Here is the code of the above
add_filter( 'the_content', 'my_the_content_filter' ); function my_the_content_filter( $content ) { global $post; if ( is_single() && $post->post_type == 'post' && $post->post_status == 'publish' ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => 0, 'post_parent' => $post->ID ) ); if ( $attachments ) { $content .= '<h3>Attachments</h3>'; $content .= '<ul class="post-attachments">'; foreach ( $attachments as $attachment ) { $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type ); $title = wp_get_attachment_link( $attachment->ID, false ); $content .= '<li class="' . $class . '">' . $title . '</li>'; } $content .= '</ul>'; } } return $content; }
I tried to change it to fit what I wanted.. by doing the following…
add_filter( 'the_content', 'my_the_content_filter' ); function my_the_content_filter( $content ) { global $post; if ( is_single() && $post->post_type == 'post' && $post->post_status == 'publish' ) { $mirrorlinks = get_posts( array( 'post_category' => 395, 'posts_per_page' => 0, 'post_parent' => $post->ID ) ); if ( $mirrorlinks ) { $content .= '<h3>Other Mirrors</h3>'; $content .= '<ul class="post-attachments">'; foreach ( $mirrorlinks as $mirrorlinks ) { $class = "post-attachment mime-" . sanitize_title( $mirorlinks->post_mime_type ); $title = wp_get_post_link( $mirrorlinks->ID, false ); $content .= '<li class="' . $class . '">' . $title . '</li>'; } $content .= '</ul>'; } } return $content; }
That gives me errors lol.
So currently, I just want to do the following, first the code gets all the posts from the links category (since thats where all the submitted posts go). Then it checks the post ID the user is currently on, and displays the links category posts that have the matching parent post IDs.
The display just includes the title, and hopefully a little excerpt.
Please guys, pretty much any help would be appreciated. The best would be some type of code that I could work with, which includes which file I should put it in (I am not very experienced with wordpress coding).
- The topic ‘Showing Attached Posts on post page’ is closed to new replies.