Show the latest image attachments from specific pages
-
I need the latest five image attachments from the specific pages to be shown on the frontpage and linked them to the page where they are attached to.
I have this theme code where it should be easily changed, but after hours and hours of searching I still can’t figure how.
<?php $categories = array( 'page-slug-one', 'page-slug-two', 'page-slug-three', 'etc' ); $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_parent' => null, 'order_by' => 'post_date', ); $images = get_posts($args); $limit = 0; if (!empty($images)) { foreach ($images AS $image) { if ($limit == 5) { break; } $post = get_post($image->post_parent); if (in_array($post->post_name, $categories)) { $limit++; $date = new DateTime($post->post_date); $formatted_date = $date->format('M j, Y'); print("<li onclick='showPage(\"" . xx_language_code() . "/" . $post->post_name . "\")'>" . $post->post_name . " (" . $formatted_date . ")</li>"); } } } else { print('<li>' . __('There are no recent images.') . '</li>'); } ?>
Obviously I want to change $post->post_name with an image but how?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Show the latest image attachments from specific pages’ is closed to new replies.