WordPress.org

Ready to get started?Download WordPress

Forums

Get Parent Post (around Attachment) (2 posts)

  1. derElch
    Member
    Posted 1 year ago #

    Well first, i hope i'm right here. My question is mostly simple, but i cant release what i want to build, so i hope i get a small help here.

    i'm rebuilding my own theme and want modify the attachment.php / image.php page.

    what i want to build is, that these pages will show the Parent Post on the attachment page too. i know i can get the information like parent Post title on an easy way:

    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>

    i thought it would be easier to build in the loop from the single.php file, which loads the content style from a own php templage file.

    <?php while ( have_posts() ) : the_post();
    
    get_template_part( 'content', get_post_format() );
    
    <?php endwhile; else: ?>
    
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    
    <?php endif; ?>

    do you know an answer? or is there a more easier way?

  2. derElch
    Member
    Posted 1 year ago #

    well mostly founded something which goes in my direction..

    <?php $recent = new WP_Query();
    $recent->query('showposts=5');
    if($recent->have_posts()) : while($recent->have_posts()): $recent->the_post();
    
    	get_template_part( 'content', 'index' ); 
    
    endwhile ?>
    <?php else : ?>
    <p> Nothing to see here. Move along </p>
    <?php endif ?>

    showing up the last 5 posts in general, how can i modify this in the parent post?

Topic Closed

This topic has been closed to new replies.

About this Topic