Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Last active October 13, 2022 03:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diggeddy/e487553c6b5749728957dad36393db4c to your computer and use it in GitHub Desktop.
Save diggeddy/e487553c6b5749728957dad36393db4c to your computer and use it in GitHub Desktop.
Simple attachment.php for GeneratePress
<?php
/**
* The Template for displaying all attachments.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header(); ?>
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
/**
* generate_before_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_main_content' );
while ( have_posts() ) : the_post();
/** display attachment */
?>
<div class="entry-attachment">
<?php if ( wp_attachment_is_image( $post->id ) ) : $att_image = wp_get_attachment_image_src( $post->id, "full"); ?>
<p class="attachment">
<img src="<?php echo $att_image[0];?>" width="<?php echo $att_image[1];?>" height="<?php echo $att_image[2];?>" class="attachment-full" alt="<?php $post->post_excerpt; ?>" />
</p>
<?php else : ?>
<a href="<?php echo wp_get_attachment_url($post->ID) ?>" title="<?php echo wp_specialchars( get_the_title($post->ID), 1 ) ?>" rel="attachment"><?php echo basename($post->guid) ?></a>
<?php endif; ?>
</div>
<?php
/** display title */
if ( generate_show_title() ) : ?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php endif;
/** Display description */
?>
<div class="entry-description">
<?php the_content(); ?>
</div><!-- .entry-caption -->
<?php
endwhile;
/**
* generate_after_main_content hook.
* @since 0.1
*/
do_action( 'generate_after_main_content' );
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
/**
* generate_after_primary_content_area hook.
*
* @since 2.0
*/
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment