wp_query returning the entire post.Returns only title

0

I have this code and when I put it on the home page it returns the entire post. I need to return only the title, date and thumbmail of the post, it is retrieving all post content ...

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;
}
    
asked by anonymous 17.12.2018 / 13:13

1 answer

0

Hello, paste this into the functions.php of your theme:

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' );

If you are assembling the page directly from a php file, call the shortcode like this:

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

If you want to display the page created inside the admin area of worpdress, simply paste the shortcode where you want:

[posts-mais-lidos]
    
21.12.2018 / 00:29