D
D
Dmitry2016-09-22 10:21:45
CMS
Dmitry, 2016-09-22 10:21:45

Why does the_content() return the content of the page and not the post?

Hello, there are several blocks on the page. Did it like this:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <div class="col-md-4 col-sm-4 col-xs-6 howWeDo__innerItem">
                        <div class="howWeDo__item">
                            <div class="howWeDo__header"><img src="<?php bloginfo('template_directory'); ?>/img/icons/howWeDo_1.png" alt="" class="howWeDo__img"></div>
                            <div class="howWeDo__footer"><?php the_post(); ?></div>
                        </div>
                    </div>
                    <?php endwhile; else: ?>
                    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
                    <?php endif; ?>

But at the same time, the_content() function displays the content of the page and not the post. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yanchevsky, 2016-09-22
@ddimonn8080

Hello.
And so?

<?php
global $post;
$post = get_post('ID_ЗАПИСИ');
if($post) : 
setup_postdata($post);
?>
<div class="col-md-4 col-sm-4 col-xs-6 howWeDo__innerItem">
  <div class="howWeDo__item">
    <div class="howWeDo__header"><img src="<?php bloginfo('template_directory'); ?>/img/icons/howWeDo_1.png" alt="" class="howWeDo__img"></div>
    <div class="howWeDo__footer"><?php the_content(); ?></div>
  </div>
</div>
<?php wp_reset_query(); endif; ?>

Instead of RECORD_ID, you need to insert the ID of the record you need.

Y
Yuri Shalaginov, 2016-09-22
@Uriy70

In theory, the POST block should be between the beginning of the if condition and its end, endif. For some reason, your condition includes a block column with Bootstrap classes:
Try like this:

<div class="col-md-4 col-sm-4 col-xs-6 howWeDo__innerItem">
                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                        <div class="howWeDo__item">
                            <div class="howWeDo__header"><img src="<?php bloginfo('template_directory'); ?>/img/icons/howWeDo_1.png" alt="" class="howWeDo__img"></div>
                            <div class="howWeDo__footer"><?php the_post(); ?></div>
                        </div>
                        <?php endwhile; else: ?>
                    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
                    <?php endif; ?>
                    </div>

Although, the markup is not entirely clear. Why do you need a block
if the image will be loaded through the admin panel in the future?
One more thing... The content of the post may not be displayed due to the absence of the single.php file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question