Using functions.php to include code that’s processed inline

After reviewing your updated code it might be better to use template parts to achieve this. The idea is that you have a directory containing various template parts, which can then be called into the document wherever you need them.

This will help clean up the template somewhat.

<?php
query_posts( 'p=1684&posts_per_page=1');
if ( get_post_status ( '1684' ) == 'publish' )
{
    /* CHECK WHETHER WATCH LIST AND WEBINAR WILL BE IN SAME ROW */
    if(($NumberConferences % 2) == 0)
    {
        get_template_part( 'template-parts/watch', 'list' );
    }
    else
    {
        get_template_part( 'template-parts/other', 'template' );
    }
}


/**
 * Template part "watch-list.php"
 * Location: wp-themes/[theme]/template-parts/watch-list.php
 */
echo '<tr>';
while( have_posts() ) : the_post();
    echo '<td>';
    echo '<div class="RightBorderLayer">';
    echo '<div class="HomeLeftCell">';
    $HomeWatchListImage = types_render_field("watch-list-home-page-image", array("raw"=>"true"));
    if($HomeWatchListImage != '')
        echo '<a href="'.get_permalink().'"><img src="'.$HomeWatchListImage.'"></a>';
    $WatchListTitles = get_post_meta($post->ID, 'wpcf-watch-list-title', false);
    $i = 1;
    foreach($WatchListTitles as $WatchListTitle)
    {
        echo '<li style="text-align: left;"><strong>Workshop '.$i.'</strong>: '.$WatchListTitle.'</li>';
        $i++;
    } // End foreach

    echo '<div class="HomePageCellNote">If you are interested in any of these events and are not regularly receiving WFCA notices, signup for our email list in the bottom left of this page.  All regular WFCA subscribers will receive notice of these events as available.</div>';
    echo '<div style="clear: both;"></div>';
    echo '</div><!-- End Home Left Cell div -->';
    echo '</div><!-- End Right Border Layer -->';
    echo '</td>';
endwhile;
wp_reset_postdata();
echo '</tr>';

If you need to pass variables from the main template to the template part you’ll need to use the following code instead:

include( locate_template( 'template-parts/watch-list.php' ) );


Old Answer (example function)

It’s a little difficult to understand what you need, however, I’ve attached some code below.

The idea behind the functions.php file is that you can create functions in there, to reference in your template. In the example below you can see there is a conditional (which always equals true). When the condition is met it runs the so_dynamic_content() function referenced in the functions.php file

The function is basic, however, it can accept parameters, i.e. layout and id, which can be used to tailor what content is displayed.

Although this doesn’t directly answer your question, it should hopefully set you on the right track. If not, add a comment and I’ll update accordingly.

<?php
/**
 * template-file.php
 */

while ( have_posts() ) : the_post();

    $the_id = get_the_ID();

    if ( 'Condition X' == 'Condition X' ) {
        so_dynamic_content( 'left', $the_id );
    } else {
        so_dynamic_content( 'right', $the_id );
    }

endwhile;

/** 
 * functions.php
 */
function so_dynamic_content( $layout, $post_id = '' ) {

    if ( $post_id == '' ) {
        global $post;
        $post_id = $post->ID;
    }

    ob_start();
    ?>

    <div class="dynamic-content <?php echo $layout; ?>">
        <p>Text</p>
        <a href="https://wordpress.stackexchange.com/questions/251782/<?php echo get_permalink( $post_id ); ?>">Anchor</a>
        <!-- HTML stuff -->
    </div>

    <?php
    $content = ob_get_clean();
    echo $content;

}