-1

Utilizo a seguinte função para montar a bio do autor que está na functions.php, mas só traz o usuário com o menor ID, deixando esse usuário como autor em todos os 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
    }

e o chamo no single.php

<?php tutsup_author_area() ?>

Íntegra do 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>
1
  • Olá amigo, o título ficou muito difuso. Se for possível, diminuia o título e seja mais descritivo na pergunta em si 2/07/2019 às 18:11

3 Respostas 3

-1

Você colocou um loop depois chamou a tua função... o loop faz com que resete a suas variáveis global post. Teria que fazer desse jeito:

<?php

$author_id = get_the_author_meta('ID');//Salva a id do author primeiro
$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;
wp_reset_postdata();//recomendo
endif;
tutsup_author_area($author_id)/// dai sim tu passa a id do autor
?>

Precisa salvar a id do autor antes do loop e depois passar ele para tua função... Recomendo também você usar o wp_reset_postdata(); depois do while

-1

Acho que o problema esta if(is_single()): ...

Ele não esta pegando o ID do Autor, não sei em que local você vai exibir isso mas se for no próprio post tenta:

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

Testei seu código, vi vários erros

Falta o:

<?php get_footer(); ?>

Mas acredito que o problema esta no loop, você precisa inserir a chamada para a função dentro dele, por exemplo:

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

Acho importante você revisar a semântica de seu html pois não é correto div dentro de a, toda section como <section class="autor"> devem ter seu heading ...

1
  • Tem get_footer(), o stackoverflow que sumiu com ele, na edição aparece 8/07/2019 às 17:08

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .