Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #352062

    I’m using single posts to display products on my site….
    but I’m wanting to only display a certain image based on category. I’ve tried to place conditional tags within the single.php file in various locations using PHP open and closing tags…but I just get a white screen no matter where I place the code in the single.php template file.

    Any assistance with this matter? It would save me hours of work adding the photos manually to roughly 100 posts.

    Thanks,`

    My example in single.php

     <?php
                        is_category( $herbicides) <a href="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/10/photo_single_post2.jpg"><img src="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/10/photo_single_post2.jpg" alt="specialty_photo_single_post" width="100%"  class= "productimage alignnone size-full wp-image-3993" /></a>;
    ?>
    #352433

    Hey BrianBookwalter!

    Thank you for using Enfold.

    The $herbicides variable doesn’t have any value. On which category are you trying to appy this image? Try to use this:

    <?php
                      if( is_category('herbicides') ) echo '<a href="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/10/photo_single_post2.jpg"><img src="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/10/photo_single_post2.jpg" alt="specialty_photo_single_post" width="100%"  class= "productimage alignnone size-full wp-image-3993" /></a>';
    ?>

    Regards,
    Ismael

    #352523

    I’m applying the image to the herbicides category.

    I can tell something is happening since when I add that PHP code you provided, I get the white screen on single.php pages only one my site.

    Basically, I have posts organized by about 5 different categories, and they are displaying in the single.php template.

    Maybe I should try that code in the functions.php file?

    I DID get the code BELOW to work in the header…but I dont’ need the images in the header…..

      <!--    <?php if(is_category('herbicides')):?>
                  <img src="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/07/Fulton.jpg">
                  <?php elseif (is_category('fungicidies')):?>
                  <img src="http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/07/Hoskins.jpg">
                  <?php endif;?>-->
    #352947

    Hi!

    Can you please provide a screenshot on how you want the category images to look on the single post pages? You should probably add the code on top of this code on single.php file:

    get_template_part( 'includes/loop', 'index' );
    						
    

    Regards,
    Ismael

    #353126
    This reply has been marked as private.
    #353404

    Still stuck after adding all types of code to single.php, or functions.php, and functions-enfold.php.

    I’m not sure if its possible to do what I’m doing considering this template and the information I’ve already put into the site.

    Any other suggestions, thanks?

    Brian

    #353732

    Hey!

    These are images that you want to add:

    http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/07/Fulton.jpg
    http://bookwalterdesign.com/albaughinc/wp-content/uploads/2014/07/Hoskins.jpg

    I’m sorry but I don’t see them on the mockup. Where do you want them to show on the single post pages? You need to edit includes > loop-index.php.

    Best regards,
    Ismael

    #353773

    On the single post pages, I’d like them to appear between the title of the product, and the beginning of the post content.

    It can be any image, really, I”m just wanting them to be category specific.

    Where would I edit the includes/ loop-index.php file and with what code? Can I an an if statement to that file?

    Best wishes,
    Brian Bookwalter

    #355796

    Hey!

    Sorry for the delay.

    You can add it on loop-index.php, find this code, right below this code:

     echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
                        echo '<span class="entry-author-link" '.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>';
                        echo '<span class="vcard author"><span class="fn">';
                        the_author_posts_link();
                        echo '</span></span>';
                        echo '</span>';
                        echo '</span>';
                    echo '</span>';
                echo '</header>';

    Use the in_category function instead of the is_category.

    if(in_category('css')) {
    					echo 'css';
    				} else if(in_category('php')) {
    					echo 'php';
    				}

    Best regards,
    Ismael

    #357976

    This worked great. Thanks for your hard work to help me.

    Follow up questions, can I experiemtn with the loop-index.php file by adding other conditional tags in different spots to affect my product posts? Just curious. Thanks again!

    #358139

    Hi!

    Yes, that is possible. It’s better if you’re working on a child theme. http://kriesi.at/documentation/enfold/using-a-child-theme/

    Cheers!
    Ismael

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Adding conditional tags to single.php’ is closed to new replies.