[Resolved] Moving Comments

Home Forums Support [Resolved] Moving Comments

Home Forums Support Moving Comments

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #589654
    Leo
    Staff
    Customer Support

    The hook part isn’t part of your original code:

    add_shortcode( 'some_content', 'insert_before_comments' );
    function insert_before_comments() {
        ob_start(); ?>
            <ul class="post-meta">
                <li>Distance: <?php echo get_post_meta($post->ID, 'Distance', true); ?></li> 
    	    <li>Time: <?php echo get_post_meta($post->ID, 'Time', true); ?></li>  
    	    <li style="font-weight:500;"><?php echo get_post_meta($post->ID, 'Download', true); ?></li>  
    	</ul>  
        <?php
        return ob_get_clean();
    }

    Then your shortcode should be [some_content]. If this doesn’t work then unfortunately we might be out of ideas.

    #589762
    Andy

    Oh I see then I’d just need to add the shortcode [some_content] at the bottom of each post when creating it?

    #589794
    Leo
    Staff
    Customer Support

    Yup or add them through the hook I suggested before.

    Untested…

    #599006
    Andy

    I’ve discovered I can just add my custom fields to the GP Hooks ‘After Content’ hook which works perfectly and then just hide/display sidebar as necessary with CSS.
    However, going forward I will need the custom fields to only display on posts in certain categories. I’ve tried the following but it doesn’t display and my sidebar and footer disappear:

    <?php if ( in_category( 'mountainbiking' )) { 
        <div class="mobile-summary" style="margin-top:30px;">
    		    <aside class="widget"> 
    		      <h2 class="widget-title" style="font-size:22px;">Route Summary</h2>
    		      	
    			    <?php the_meta(); ?>
    		    </aside>	
    	</div>
    }
    ?>
    #599217
    Leo
    Staff
    Customer Support

    Try in_category( 'mountainbiking' ) && is_single()

    #599238
    Andy

    Here’s my full code now but it’s still not working:

    <?php if ( in_category( 'mountainbiking' ) && is_single() ) { 
        <div class="mobile-summary" style="margin-top:30px;">
    		    <aside class="widget"> 
    		      <h2 class="widget-title" style="font-size:22px;">Route Summary</h2>
    		      	
    			    <?php the_meta(); ?>
    		    </aside>	
    	</div>
    }
    ?>

    Just to clarify, if I remove the if statement and just leave the HTML and custom fields they display fine.

    #599598
    Tom
    Lead Developer
    Lead Developer

    Try this instead:

    <?php if ( in_category( 'mountainbiking' ) && is_single() ) {  ?>
        <div class="mobile-summary" style="margin-top:30px;">
    		    <aside class="widget"> 
    		      <h2 class="widget-title" style="font-size:22px;">Route Summary</h2>
    		      	
    			    <?php the_meta(); ?>
    		    </aside>	
    	</div>
    <?php } ?>
    #599872
    Andy

    Thank you Tom, works like a charm. Obviously didn’t quite have my PHP syntax correct.

    #600075
    Tom
    Lead Developer
    Lead Developer

    No problem, glad I could help 🙂

Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.