Tuesday, November 8, 2022
HomeWordPress DevelopmentTips on how to print completely different informations for various submit varieties...

Tips on how to print completely different informations for various submit varieties inside The Loop?


I’ve a homepage that’s mixing two post-types : submit and occasions

My purpose is to print the main points of every occasion to be able to differentiate the content material.

That is the strategy that I used to combine posts and occasions contained in the Loop :

// The Question
        $args = array(
           'post_type' => array( 'submit', 'occasion', 'e book' )
            );
    
        $question = new WP_Query( $args );

Within the Loop, I’m printing the title, the excerpt and I’m wondering whether it is attainable then to introduce a situation (contained in the Loop) to confirm of that is an occasion after which retrieve some particulars about it. It seems to be precisely like this:

// The Loop
        
        if ( $query->have_posts() ) : ?>

        <?php if ( is_home() && ! is_front_page() ) : ?>
            <header>
                <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
            </header>
        <?php endif; ?>

        <?php
        // Begin the loop.
        whereas ( $query->have_posts() ) :
            $query->the_post();

            /*
             * As a substitute of publishing all of the content material, on residence web page we solely get the title, the thumbnail and an excerpt
             */
        the_title( '<h1 class="entry-title">', '</h1>' );
        the_excerpt() ;
        
        // Check if that is an occasion after which print particulars
        if (is_singular('occasion') ) {
            eo_get_template_part( 'event-meta', 'event-single' );
        }

            // Finish the loop.
        endwhile;

I’m not actually certain that I’m utilizing the most effective strategy on this. I’ve seen that there’s additionally one other approach to combine contents by modifying the worldwide question in capabilities.php

Somebody right here can please inform me how can accomplish this ?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments