I
I
id_ox2018-05-07 22:56:41
WordPress
id_ox, 2018-05-07 22:56:41

How to embed php into php?

Hello!
There is a page with the output of records from wp

<?php
/**
 * The default template for displaying content
 *
 * Used for masonry blog
 *
 */
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('post-in-blog '); ?>> 
<div class="post-masonry"> <a href="<?php the_permalink(); ?>" >
        <!-- <?php if (has_post_thumbnail() && !post_password_required() && !is_attachment()) : ?>
            <div class="entry-thumbnail"> 
                <a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail('mp-emmet-thumb-medium-masonry'); ?></a>
        </div>
        <?php endif; ?> -->
        <header class="entry-header">
            <h2 class="entry-title h5">
               <?php echo (get_post_meta($post->ID, 'sq', true)); ?>
            </h2>            
        </header> 
      <section class="entry-content">
            <p>
                <?php
                echo (get_post_meta($post->ID, 'etazh', true));
                ?>
            </p>
        </section>
        <footer class="entry-footer">
            <div class="meta">
                <span class="date-post h6"><?php echo (get_post_meta($post->ID, 'class', true)); ?></span>
                <?php if (comments_open()) : ?>
                    <a class="comments-count" href="<?php if(!is_single()):the_permalink(); endif; ?>#comments" >
                        <span class="fa fa-comments-o"></span><span><?php comments_number('&nbsp;0', '&nbsp;1', '&nbsp;%'); ?></span>
                    </a>
                <?php endif; ?>
                <div class="clearfix"></div>
            </div>
        </footer>
  </a> </div> 
</article>
<!-- #post -->

Help bring it to the theme block (php) on the main page. Through get_template_part it is not displayed correctly, or rather not at all as it should be. There is a piece of css styles, but the information is missing.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2018-05-08
@PavelK

Good day.
Apparently this code should be in any cycle where posts are displayed.
Read: https://codex.wordpress.org/The_Loop

I
id_ox, 2018-05-08
@id_ox

Did it like this:

<?php
/*
 * portfolio section
 */
?> 
<div class="container main-container">
    <div class="row clearfix">
        <div class=" masonry-blog masonry">
  <?php $query = new WP_Query('content-masonry'); ?>
 <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('post-in-blog '); ?>> 
  <div class="post-masonry"> <a href="<?php the_permalink(); ?>" >
 <header class="entry-header">
            <h2 class="entry-title h5">
               <?php echo (get_post_meta($post->ID, 'sq', true)); ?>
            </h2>            
</header>
      <section class="entry-content">
            <p>
                <?php
                echo (get_post_meta($post->ID, 'etazh', true));
                ?>
            </p>
        </section>
     <footer class="entry-footer">
            <div class="meta">
                <span class="date-post h6"><?php echo (get_post_meta($post->ID, 'class', true)); ?></span>
         <div class="clearfix"></div>
         </div>
        </footer>
      </a> </div> 
</article>
 <?php endwhile; ?>
<?php endif; ?>
</div>
    </div>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question