Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:40:23+00:00 2026-06-05T13:40:23+00:00

Okay, I’ve set up a bit of code which searching for all the pages

  • 0

Okay, I’ve set up a bit of code which searching for all the pages which are a child of the ID 8, then outputs all the attachments (in the gallery) of these pages as unordered list items. You can see the effect so far here http://goo.gl/eq4UF.

The problem I’m having is that I need to include the title of each page before each so you can easily identify which images come below which page. Normally I would just add this in, but the list items al use masonry and are positioned all over the page using some JS so they never appear beside the first image in the list.

I therefore will add the title of the page to every
<li> in the <ul> which will allow the title to run with each image but I don’t know how to include this in the wp get attachment image function. Both the_title and wp_title doesn’t work inside this loop. apply_filters( 'the_title', $attachment->post_title ); obviously takes the image title, but is there any good to take the page title?

Thanks in advance and hope this made sense,
R

<?php $postslist = get_pages('number=9999&sort_order=DESC&sort_column=post_date&child_of=8');
foreach ($postslist as $post) :
setup_postdata($post); ?>
<ul class="main-projects-list">
<?php

$args = array(
   'post_type' => 'attachment',
   'numberposts' => -1,
   'post_status' => null,
   'post_parent' => $post->ID,
   'orderby' => 'menu_order',
   'order' => 'ASC',
  );

  $attachments = get_posts( $args );
     if ( $attachments ) {
        foreach ( $attachments as $attachment ) {
           echo '<li class="each-image">';
           echo wp_get_attachment_image( $attachment->ID, 'large' );
           echo '<p>';
           echo apply_filters( 'the_title', $attachment->post_title );
           echo '</p></li>';
          }
     }

?>
</ul>
<?php endforeach; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:40:24+00:00Added an answer on June 5, 2026 at 1:40 pm

    You can try this:

    <?php $postslist = get_pages('number=9999&sort_order=DESC&sort_column=post_date&child_of=8');
    foreach ($postslist as $post) :
    setup_postdata($post); ?>
    <ul class="main-projects-list">
    <?php
    
    $args = array(
       'post_type' => 'attachment',
       'numberposts' => -1,
       'post_status' => null,
       'post_parent' => $post->ID,
       'orderby' => 'menu_order',
       'order' => 'ASC',
      );
    
      $attachments = get_posts( $args );
         if ( $attachments ) {
            $post_title = get_the_title($post->ID); // We get the post title
            foreach ( $attachments as $attachment ) {
               $img_title = apply_filters( 'the_title', $post_title . ' - ' . $attachment->post_title ); // We create the image title with the 2 strings
               echo '<li class="each-image">';
               echo wp_get_attachment_image( $attachment->ID, 'large' , false, array('title' => $img_title));
               echo '<p>';
               echo $img_title;
               echo '</p></li>';
              }
         }
    
    ?>
    </ul>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so here is what I'm trying to accomplish. First of all below table
Okay, so I have the weirdest problem right now. My code is fine! It
Okay say your using a app, and you opened a new activity and then
Okay so my question is this. Say I have a simple C++ code: #include
Okay so the title may be a bit misleading. What I am trying to
Okay, this is the case: I got a generic base-class which I need to
okay, I know I am new to obj-c, but for all intents and purposes
Okay, I'm reading about Linux kernel development and there are some code snippets using
Okay, I've looked all over the internet for a good solution to get PHP
Okay im making a mobile application using jquery, and then im using phonegap to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.