• Resolved SpartanCopy

    (@spartancopy)


    Hi wordpress gurus.

    I am having great difficulty trying to call information from a page that is a sub-page to another parent, and I was hoping someone would be able to help.

    Basically I have built a website that as well as the usual home, about and content page includes a shop that which has 3 levels of hierarchy.

    The store.
    – The categories. Sub-pages of the store.
    — The products. Sub-pages of the categories.

    Throughout the entire site I call a sidebar <aside> which displays the title and a snippet of the latest blog post and I’ve added a mailing list form. This bit I have done.

    However I also want to add a “latest design” section. This would display as a link the title of the newest sub-page of a specific category. As well as an image defined by a custom field.

    • The category title is Designs and has a page id of 22.
    • Each product has an image defined using a custom field called
      “Product_Image”
      .

    I know the code to display it is:

    <a href="<?php the_permalink(); ?>">
            <h3><?php the_title(); ?></h3>
            <?php  echo "<img src='" . get_post_meta($post->ID, "Product_Image", true) . "' />"; ?>
           </a>

    Unfortunately I do not know how to call from the newest sub-page of a specific parent. As you can tell I am new to PHP and have I am only just beginning to learn PHP from Lynda.com.

    Could anyone help please?

    Also as a side note is there a way to define a featured product. I was thinking of having an “item of the week” so the same info as above (title, image, permalink) can be called from a specified product page and displayed on the home page. But the featured product could then be changed from week to week?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter SpartanCopy

    (@spartancopy)

    I have managed to find this but I do not know how to change it so it only calls the newest sub-pages of my design page, rather than calling the last 5 pages of the whole site.

    <?php
       $args=array(
       'showposts'=>5,
       'post_type' => 'page',
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <div>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
            <?php  echo "<img src='" . get_post_meta($post->ID, "Product_Image", true) . "' />"; ?>
          </a>
        </div>
      <?php
      endwhile;
    }
    ?>
    Thread Starter SpartanCopy

    (@spartancopy)

    Turns out all you have to do is add one line to the initial argument. (change 22 to the ID of the parent page)

    'post_parent' => '22'

    so it becomes

    $args=array(
       'showposts'=>5,
       'post_type' => 'page',
       'caller_get_posts'=>1,
       'post_parent' => '22'
       );

    Remember to add a comma , to the line before ‘post_parent’ so it knows it is a different argument.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display title and img from a sub-page that is not child to current page’ is closed to new replies.