Tagged: category, single.php
-
AuthorPosts
-
November 16, 2014 at 5:17 pm #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>; ?>
November 17, 2014 at 2:55 pm #352433Hey 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,
IsmaelNovember 17, 2014 at 4:49 pm #352523I’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;?>-->
November 18, 2014 at 1:59 pm #352947Hi!
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,
IsmaelNovember 18, 2014 at 6:05 pm #353126This reply has been marked as private.November 19, 2014 at 1:02 am #353404Still 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
November 19, 2014 at 3:41 pm #353732Hey!
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.jpgI’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,
IsmaelNovember 19, 2014 at 4:33 pm #353773On 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 BookwalterNovember 22, 2014 at 6:53 am #355796Hey!
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,
IsmaelNovember 25, 2014 at 10:09 pm #357976This 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!
November 26, 2014 at 4:58 am #358139Hi!
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 -
AuthorPosts
- The topic ‘Adding conditional tags to single.php’ is closed to new replies.