wp_query returning the entire post. Returns only title

Asked

Viewed 42 times

0

I have this code and when I put it on the Home Page it returns the entire post. I need you to return only the title, date and thumbmail of the post, is recovering all content of the 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;
}
  • tries to remove this part: "the_post();"

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 mounting the direct page of a php file, call the shortcode like this:

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

If you want to view from the page created within the admin area of worpdress, simply paste the shortcode where you want:

[posts-mais-lidos]

Browser other questions tagged

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