0

Tenho esse código e quando eu coloco ele na Home Page ele retorna o post inteiro. Preciso que retorne apenas o titulo,data e thumbmail do post, está recuperando todo conteudo do post...

function get_mais_lidos_semana() {
global $wpdb;
global $post;

ob_start();
$week = date('W');
$year = date('Y');
query_posts('post_type=post&posts_per_page=5&meta_key=post_views_count&orderby=meta_value_num&ignore_sticky_posts=1&year=' . $year . '&w=' . $week);

$text = '<div class="td_block_inner">';

while (have_posts()):
    the_post();

    $text .= '
        <div class="td-block-span12">
            <div class="td_module_6 td_module_wrap td-animation-stack">
                <div class="td-module-thumb">
                    <a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">
                        '.get_the_post_thumbnail().'
                    </a>
                </div>
                <div class="item-details">
                    <h3 class="entry-title td-module-title">
                        <a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">
                            '.get_the_title().'
                        </a>
                    </h3>
                    <div class="td-module-meta-info">
                        <span class="td-post-date">
                            <time class="entry-date updated td-module-date">
                                '.get_the_date().'
                            </time>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    ';
endwhile;
$text .= '</div>';
wp_reset_query();
echo $text;
}
1
  • tenta remover essa parte: "the_post();"
    – Victor M.
    18/12/2018 às 11:15

1 Resposta 1

0

Olá, cola isso no functions.php do teu tema:

function get_mais_lidos_semana() {

$query = new WP_Query( array(
    'post_type' => 'post',
    'posts_per_page' => 5,
    'orderby' => 'meta_value_num',
    'meta_key' => 'post_views_count'
) );

ob_start(); ?>

<div class="td_block_inner">
<?php while ( $query->have_posts() ): $query->the_post(); ?>

    <div class="td-block-span12">
        <div class="td_module_6 td_module_wrap td-animation-stack">
            <div class="td-module-thumb">
                <a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">
                    <?php the_post_thumbnail(); ?>
                </a>
            </div>
            <div class="item-details">
                <h3 class="entry-title td-module-title">
                    <a href="'.get_the_permalink().'" title="'.get_the_title().'" rel="bookmark">
                        <?php the_title(); ?>
                    </a>
                </h3>
                <div class="td-module-meta-info">
                    <span class="td-post-date">
                        <time class="entry-date updated td-module-date">
                            <?php the_date() ?>
                        </time>
                    </span>
                </div>
            </div>
        </div>
    </div>

<?php endwhile; ?>
</div>
<?php return ob_get_clean();
}
add_shortcode( 'posts-mais-lidos', 'get_mais_lidos_semana' );

Se estiver montando a página direto de um arquivo php, chame o shortcode assim:

<?php echo do_shortcode( '[posts-mais-lidos]' ); ?>

Se quiser exibir pela página criada dentro da área admin do worpdress, simplesmente cole o shortcode onde quiser:

[posts-mais-lidos]

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 .