Support » Developing with WordPress » Props data and WordPress template parts?

  • Hi,

    Is there a way to send the data as **props in** some of the **template parts**?

    My idea is next :

    ### index.php or any file to the theme hierarchy.
         if ( have_posts() ) : 
              while ( have_posts() ) : the_post();
         $permaLink = the_permalink(); 
         $author = the_author();
         $postData = array($permaLink,$author...);
         get_template_part( 'template-parts/one-blog-post', $postData );
    ### template part one-blog-post.php
    ### commet area
        $propsData = get_props();
        <div class="box">
              <a href="<?php $propsData['permaLink']?>"/>
              <p>Posted by <?php $propsData['author'] ?></p>

    **get_props();** function.

    Is it possible to do something like this?

Viewing 1 replies (of 1 total)
  • Joy


    You can, but it’s kind of hacky. It is better as a separate function that takes parameters, since the variables are made global.
    Read this contributor note about query vars.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.