在wordpress functions.php函数中返回函数的语法是什么?

时间:2016-05-13 00:45:50

标签: php wordpress

在wordpress的另一个返回函数中调用返回函数的适当解决方案是什么?

这是我得到的:

// Related Posts Function, matches posts by tags - call using joints_related_posts(); )
function joints_related_posts() {
global $post;
$tags = wp_get_post_tags( $post->ID );
if($tags) {
    foreach( $tags as $tag ) {
        $tag_arr .= $tag->slug . ',';
    }
    $args = array(
        'tag' => $tag_arr,
        'numberposts' => 1, /* You can change this to show more */
        'post__not_in' => array($post->ID),
        'post_views_count','orderby' => 'DESC'
    );
    $related_posts = get_posts( $args );
    if($related_posts) {
    echo '<related-h4>SEE MORE:</related-h4>';
    echo '<related-post id="joints-related-posts">';
        foreach ( $related_posts as $post ) : setup_postdata( $post ); ?>
            <li class="related_post">
                <a class="entry-unrelated" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                <?php get_template_part( 'partials/content', 'byline' ); ?>
            </li>
        <?php endforeach; }
        }
wp_reset_postdata();
echo '</ul>';
}


add_filter( 'the_content', 'prefix_insert_post_ads' );

function prefix_insert_post_ads( $content ) {

$related_posts_code = 'return joints_related_posts()';

if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( ($related_posts_code), 2, $content );
}

return $content;
}

函数return joints_related_posts()是我在函数return prefix_insert_after_paragraph(中尝试调用的函数,我该怎么做?

0 个答案:

没有答案