get_the_author and no function to get information from the author of the post works on the theme

Asked

Viewed 219 times

0

I use the following function to assemble the author’s bio that is in functions.php, but only brings the user with the smallest ID, leaving this user as author in all posts.

function tutsup_author_area(){
        if(is_single()):
            $author_id = get_the_author_meta('ID');
?>

            <section class="autor">
                <div class="foto-autor" style="background-image: url(<?php echo get_avatar_url( get_the_author_meta( 'user_email' ), 250 ); ?>)"></div>
                <div class="descricao-autor">
                    <div class="nome-autor"><?php echo get_the_author(); ?></div>
                    <div class="info-autor"><?php the_author_meta( 'description' ); ?></div>
                    <div class="rede-sociais-autor">
                        <?php if (get_the_author_meta('twitter', $author_id)):?>
                            <a class="link-redes-sociais-autor" href="<?php echo get_the_author_meta('twitter', $author_id); ?>" target="_blank"><i class="fab fa-twitter"></i></a>
                        <?php endif; ?>
                        <?php if ( get_the_author_meta( 'facebook', $author_id ) ): ?>
                            <a class="link-redes-sociais-autor" href="<?php echo get_the_author_meta( 'facebook', $author_id ); ?>" target="_blank"><i class="fab fa-facebook-f"></i></a>
                        <?php endif;?>
                        <?php if ( get_the_author_meta( 'instagram', $author_id ) ): ?>
                            <a class="link-redes-sociais-autor" href="<?php echo get_the_author_meta('instagram',$author_id); ?>" target="_blank"><i class="fab fa-instagram"></i></a>
                        <?php endif; ?>
                    </div>
                </div>
            </section>
        <?php endif; ?>
<?php
    }

and call you in single.php

<?php tutsup_author_area() ?>

Full version of the single.php

<?php get_header(); ?>
<main>
    <section class="noticia">
        <div class="alinhamento-noticias">
            <div class="corpo-noticia">
                <div class="imagem-noticia" style="background-image: url(<?php the_post_thumbnail_url('corte_quadrado_grande') ?>);"></div>
                <div class="titulo-noticia">
                    <h1><?php the_title() ?></h1>
                    <time datetime="<?php the_modified_time('c'); ?>">
                       <?php echo 'Publicado: '.get_the_time('d \d\e F \d\e Y').' | Modificado: '.get_the_modified_time('d \d\e F \d\e Y'); ?>
                    </time>

                </div>
                <div class="texto-noticia">
                    <p>
                    <?php echo $post -> post_content ?>
                    </p>
                </div>
            </div>
            <div class="ultimas-editoria">
            <?php
            $the_cat = the_category_ID ('');
            $the_post_id = get_the_ID();    
            $args_post = array('post_type' => 'post', 'posts_per_page' => 5, 'cat' => $the_cat, 'post__not_in' => array($the_post_id));
            $the_query_post = new WP_Query( $args_post );
            if($the_query_post -> have_posts()):
                while($the_query_post -> have_posts()):
                    $the_query_post ->the_post();
            ?>
                <a href ="<?php the_permalink()?>" class="ultimas-editoria-cor">                        
                        <div class="img-noticia ultimas-editoria-cor" style="background-image: url(<?php the_post_thumbnail_url('corte_quadrado_pequeno') ?>)"></div>                      

                        <div class="texto-noticia-editoria">
                            <p> <?php the_title() ?> </p>
                        </div>

                </a>
            <?php                   
             endwhile;
            endif;
            ?>
            </div> 
        </div>        
    </section>
    <?php tutsup_author_area() ?>
    <?php 
        $categoriaNome = get_cat_name( the_category_ID('') );
        echo '<input type="hidden" id="pegar-categoria" value="'.$categoriaNome.'"/>';
    ?> 
    <script src="<?php bloginfo('template_directory') ?>/js/pegar-redes-sociais.js"></script>
    <script src="<?php bloginfo('template_directory') ?>/js/cor-por-categoria-single.js"></script>            
</main>
<?php comments_template(); ?>
<script>
    var disqus_config = function () {
    this.language = "pt_BR";
    };
</script>
  • Hello friend, the title was very diffuse. If possible, decrease the title and be more descriptive in the question itself

2 answers

0

I tested your code, saw several errors

The:

<?php get_footer(); ?>

But I believe the problem is in the loop, you need to insert the call to the function inside it, for example:

<div class="texto-noticia-editoria">
    <p><?php the_title() ?></p>
    <?php tutsup_author_area() ?>
</div>

I find it important that you review the semantics of your html because it is not correct to div inside a, toda <section class="autor"> should have your Heading ...

  • Has get_footer(), the stackoverflow that disappeared with it, in the edition appears

0

I think the problem is if(is_single()): ...

He’s not getting the author ID, I don’t know where you’ll display it but if it’s in the post itself try:

if(is_singular('')): ... 
 // ou 
if(is_singular('post')): ... 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.