Single.php

For a question on StackOverflow
mail@pastecode.io avatar
unknown
html
7 months ago
3.2 kB
6
Indexable
Never
<?php get_header(); ?>
<div class="article-container">
    <div class="article-body">
        <div class="article-heading">
            <?php the_title(); ?>
            <div class="publishing-data">
                <?php the_author_meta('display_name', 1); ?>
                <p>&nbsp;•&nbsp;</p>
                <?php the_time( 'j F, Y' );?>
            </div>
        </div>
        <div class="article-mainfocus">
            <div class="article-content">
                <?php the_content(); ?>
            </div>
            <div class="side-content">
                <p>Fotos</p>
                <div class="sc-images">
                <?php
                    $images = get_attached_media( 'image' );
                    $i = 2;

                    if ( $images ) {
                        foreach( $images as $image ) {
                            $image_attributes = wp_get_attachment_image_src( $image->ID, 'full' );

                            if ( $image_attributes ) {
                                ?>
                                <div class="sc-image<?php echo ( $i % 3 === 0 ) ? ' new-row' : ''; ?>">
                                    <a href="#" data-bs-toggle="modal" data-bs-target="#image-modal-<?php echo $i; ?>">
                                        <img src="<?php echo esc_url( $image_attributes[0] ); ?>" alt="<?php echo esc_attr( $image->post_title ); ?>" />
                                    </a>
                                </div>
                                <?php
                                $i++;
                            }
                        }
                    }
                ?>
                </div>
                <p>Tags</p>
                <div class="sc-tags">
                    <?php
                    $tags = get_the_tags(); // Retrieve tags for current post

                    if ($tags) { // Check if tags exist for the post
                        foreach($tags as $tag) { // Loop through tags
                            echo '<a class="sc-tag" href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>'; 
                        }
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Image Modal -->
<?php
$i = 1;
foreach($images as $image) {
    $image_attributes = wp_get_attachment_image_src( $image->ID, 'full' );
    ?>
    <div class="modal fade" id="image-modal-<?php echo $i; ?>" tabindex="-1" aria-labelledby="image-modal-<?php echo $i; ?>-label" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-body">
                    <img src="<?php echo $image_attributes[0]; ?>" alt="<?php echo $image->post_title; ?>" />
                </div>
                <div class="modal-header">
                    <h5 class="modal-title" id="image-modal-<?php echo $i; ?>-label"><?php echo $image->post_title; ?></h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
            </div>
        </div>
    </div>
    <?php
    $i++;
}
?>
<?php get_footer(); ?>