-1

Is there a way to implement a single loop with dual content area.

E.g. A single loop having 2 of

<?php the_content(); ?>

Dinstinguished as shown bellow with video and write-up respectively

<?php the_content('video'); ?>

<?php the_content('write-up'); ?>
  • 3
    The first argument in the_content() is $more_link_text, I am not sure I am following what are you trying to achieve with that? – Rarst Sep 9 '14 at 15:28
2

Lets first start with a bit of knowledge-base: the_content is this

/**
 * Display the post content.
 *
 * @since 0.71
 *
 * @param string $more_link_text Optional. Content for when there is more text.
 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
 */
function the_content( $more_link_text = null, $strip_teaser = false) {
    $content = get_the_content( $more_link_text, $strip_teaser );
    $content = apply_filters( 'the_content', $content );
    $content = str_replace( ']]>', ']]&gt;', $content );
    echo $content;
}

For more information on how the content is generated check: get_the_content()

So the video and write-up will be $more_link_text values generating at a <a href="...">$more_link_text</a>

Now back to you

If in your content you have information that you want to be filtered (divided / separated) in two areas do this:

add_filter('the_content', 'filter_only_video')
the_content();
remove_filter('the_content', 'filter_only_video');

add_filter('the_content', 'filter_only_write')
the_content();
remove_filter('the_content', 'filter_only_write');

And in functions.php add this:

function filter_only_video($content) {
    // your code that only keeps that video part on (removing the rest)
    return $content;
}

function filter_only_write($content) {
    // your code that only keeps write-up part on (removing the rest)
    return $content;
}

If you write these two functions correctly you can show what you want in two separate places.

1

Take a look at the default Twenty Fourteen theme code in index.php

<?php
    if ( have_posts() ) :
        // Start the Loop.
        while ( have_posts() ) : the_post();

            /*
             * Include the post format-specific template for the content. If you want to
             * use this in a child theme, then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            get_template_part( 'content', get_post_format() );

        endwhile;
        // Previous/next post navigation.
        twentyfourteen_paging_nav();

    else :
        // If no content, include the "No posts found" template.
        get_template_part( 'content', 'none' );

    endif;
?>

The above code uses get_template_part(); Which I believe is what you're trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.