Amy-Mir / global-templates / single-post.php
single-post.php
Raw
<?php
/**
 * The template part for displaying post page sidebar
 * 
 * @uses Parent div tag class attribute "blogCards__container" to init stylings
 *  
 */
    
$socialMedia = get_field('social_media_links','options');

$post_cover = get_field("cover", get_the_ID(  ));
$post_title = get_the_title( );
$post_introduction = get_field("introduction", get_the_ID(  ));
$post_category = get_the_category( )[0]->name;
$post_comments_count = get_comment_count(get_the_ID(  ))["approved"];

$post_content = null;

if( $post_category === "Blog Post" ) {
    $post_content = get_field("content", get_the_ID(  ));
} else if ( $post_category === "Podcast" || $post_category === "Tv-show" ) {
    $post_content = get_field("post_embed_url", get_the_ID(  ));
}


$previous_post = get_previous_post();
$next_post = get_next_post();
$post_tags = wp_get_post_tags(get_the_ID( ));

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

?>

<article>
    <div class="article__cover">
        <img alt="<?php echo esc_attr($post_cover['alt']); ?>" class="lazy"
            src="<?php echo esc_attr($post_cover['sizes']['thumbnail']); ?>"
            data-src="<?php echo esc_attr($post_cover['sizes']['large']); ?>" 
            data-srcset="<?php echo esc_attr($post_cover['sizes']['medium']); ?> 300w,
            <?php echo esc_attr($post_cover['sizes']['large']); ?> 768w,
            <?php echo esc_attr($post_cover['sizes']['1536x1536']); ?> 1024w" 
            data-sizes="100w" />
    </div>
    <div class="article__title">
        <h1 class="heading1"><?php echo esc_html($post_title) ?></h1>
    </div>
    <div class="article__extras">
        <?php echo process_post_cat(get_the_ID(), true); ?>
        <div class="cmt_count">
            <spna class="far fa-comment-alt"></spna>
            <span><?php echo esc_html($post_comments_count)?> Kommentarer</span>
        </div>
    </div>
    <div class="article__intro">
        <p class="paragraph"><?php echo esc_html($post_introduction); ?></p>
    </div>
    <div class="article__content <?php echo esc_attr($post_category === "Podcast" ? "--playerWidth" : "") ?>">
        <?php echo $post_content?>
    </div>
</article>

<section class="article__footer">
    <?php if(sizeof($post_tags) > 0): ?>
        <div class="postTags__wrapper">
            <ul>
            <li class="btnText__lg">Tagger:</li>
                <?php foreach($post_tags as $tag): ?>
                    <li><?php echo esc_html($tag->name) ?></li>
                <?php endforeach; ?>
            </ul>
        </div>
        <hr>
    <?php endif; ?>
    <div class="inters__wrapper">
        <div class="inters__shares">
            <span class="btnText__lg">Del:</span>
            <div class="inters__sharebtns">
                <a 
                    href="https://www.facebook.com/sharer/sharer.php?u=<?php echo esc_attr(get_permalink());?>"
                    target="_blank" rel="noopener noreferrer"
                    >
                    <span class="fab fa-facebook-f"></span>
                </a>
                <a 
                    href="https://twitter.com/intent/tweet?url=<?php echo esc_attr(get_permalink());?>&text=<?php echo get_the_title();?>"
                    target="_blank" rel="noopener noreferrer"
                    >
                    <span class="fab fa-twitter"></span>
                </a>
                <a 
                    href="https://pinterest.com/pin/create/button/?url=<?php echo esc_attr(get_permalink());?>&media=<?php echo esc_attr($post_cover['sizes']['medium']); ?>&description=<?php echo esc_html($post_introduction); ?>"
                    target="_blank" rel="noopener noreferrer"
                    >
                    <span class="fab fa-pinterest"></span>
                </a>
                <a 
                    href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo esc_attr(get_permalink());?>"
                    target="_blank" rel="noopener noreferrer"
                    >
                    <span class="fab fa-linkedin-in"></span>
                </a>
            </div>
        </div>
        <div class="inters__main">
            <?php echo get_simple_likes_button( get_the_ID() ); ?>
        </div>
    </div>
</section>

<section>
    <?php comments_template(); ?>
</section>

<section class="post__relations">
    <div class="npcards__wrapper">
        <?php 
        
        if(!!$previous_post):

            $args = array(
                "post_id"   => $previous_post->ID,
                "type"      => "prev"
            );
            get_template_part( "global-templates/nextprev", "card", $args );

        endif;
        
        if(!!$next_post):

            $args = array(
                "post_id"   => $next_post->ID,
                "type"      => "next"
            );
            get_template_part( "global-templates/nextprev", "card", $args );
        
        endif;
        ?>
    </div>
    <div class="page__title">
        <span class="btnText__lg">Relaterte innlegg</span>
        <hr>    
    </div>
    <div class="recards__wrapper">
        <?php         
        get_template_part( "global-templates/related", "posts" );
        ?>
    </div>
    
</section>