• In my index.php, I have

    <?php
                if(have_posts()) :
                    while(have_posts()) : the_post();
                        echo cool_post_article_normal_block();
                    endwhile;
                endif;
    ?>

    So in funcitons cool_post_article_normal_block() says…

    link -> https://pastebin.com/WDDJC6ks

    What I understand is that I’m supposed to modify between <article></article>but what I don’t know how to do is get the post format conditionally; especially since there is already a sticky conditional– and I don’t know PHP well ??

    I’m very new to PHP so I’m unsure how to do this. I have several post formats activated: quote, video, gallery, audio, image.

    I’d like the loop to go something like:

    if sticky
    if quote
     show title only
    if video, audio, gallery
     show title
     show excerpt
    if image
     show title
     show featured image
    else
    if quote
     show title only
    if video, audio, gallery
     show title
     show excerpt
    if image
     show title
     show featured image

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m rather late in replying, maybe I can still be of some help. You can get the post format with get_post_format(). Since you would be possibly using the returned value multiple times, it’d be best to assign it to a variable first. Then you can write conditionals like so:

    $format = get_post_format();
    if ( 'video'== $format || 'audio'== $format ) {
       the_title();
       the_excerpt();
       //the_content(); //if using <!--more--> quick tags
       echo get_the_featured_image();
    }

    I’ve excluded the surrounding HTML used to nicely format the output, you can work off the current code for that. I’ve also used more template tags than you would want in one place, pick and choose which ones you want to use. You seem to understand how you want the logic applied, you just need to convert your pseudocode to proper PHP, mainly a matter of proper syntax. If you define WP_DEBUG as true in wp-config.php, PHP will pretty much tell you what and where you went wrong. Just go back and fix it ??

    Yeah, easier said than done. Give it a go anyway, if you get stuck, let us know and we can set you straight.

Viewing 1 replies (of 1 total)
  • The topic ‘Post Formats in Loop (loop in function w/sticky)’ is closed to new replies.