Jump to content
Sign in to follow this  
buddhistwhatson

display text on specific category posts using php

Recommended Posts

buddhistwhatson

Hi; I'm using Advanced Custom Fields for certain post categories. The fields display fine, but i want to display a title for each field. this is my code in template.postloop.php --------------- <div class="cday"><b>Day of Class:/b> /div> <div class="day"><?php the_field('day'); ?></div> --------------- the code is working fine, but i only want to display "Day of class" on those posts in certain categories ex.. 71,72. I tried using ----- <?php if( is_category('78, 81, 82, 83, 84, 85, 86, 21') ) echo 'Hello';?> as a test in the template.postloop file but it didnt work. Can you please advise what code and what file to use? www (dot) buddhistwhatson (dot) com Thank you

Share this post


Link to post
Share on other sites
jacopo3001

hi, i have a related question.(i am brand new to pagelines) I want to customize the look of a category. If i was on a basic template, I would create a loop-category-[slug].php but here? fyi, What I want to do is to print specific custom fields in the loop

Share this post


Link to post
Share on other sites
buddhistwhatson

Hi that works great to display hello. Thank you. Now can you tell me how to put my ACF code inside of it? Here is the code. Thanks ------------- <?php if( in_category( array( 78, 81, 82, 83, 84, 85, 86, 21 ) ) ) echo 'Hello'; ?> <div class="stitle"> <h3><?php the_field('class_stitle'); ?></h3></div> <div class="cday"> <b>Day of Class: </b></div> <div class="day"><?php the_field('day'); ?></div> <div class="cteacher"><b>Teacher: </b> </div> <div class="teacher"><?php the_field('teacher'); ?></div> <div class="cfee"> <b>Class Fee: </b> </div> <div class="fee"><?php the_field('fee');</div> <div class="description"><?php the_field('description'); ?></div> <div class="cemail"><b>Email: </b> </div> <div class="email"><?php the_field('cemail'); ?></div> <div class="caddress"><b>Address: </b> </div> <div class="address"><?php the_field('address'); ?></div> <div class="csite"><b>Website: </b> </div> <div class="cwebsite"><?php the_field('website'); ?></div> <div class="ccontact"> <b>Contact: </b></div> <div class="contactp"><?php the_field('contactp'); ?></div> <div class="cimage"> " /> </div> <div class="imagepos"><?php the_field('page_image_position'); ?>" </div>; ------------- the "the_field" items already print on the correct category page,but the other (ex: Teacher) ones dont. Please tell me how i can use the code above to make them appear only on those category pages. ps. i put all of my code where "hello" is in the "php if" line , with and without the echo but it didnt work. Thank you

Share this post


Link to post
Share on other sites
buddhistwhatson

Hi.i think i worked it out , need to use in_category here is what worked --------- <?php if( in_category( array( 78, 81, 82, 83, 84, 85, 86, 21 ) ) ) { ?> <div class="stitle"> <h3><?php the_field('class_stitle'); ?></h3></div> <div class="cday"> <b>Day of Class: </b></div> <div class="day"><?php the_field('day'); ?></div> <div class="cteacher"><b>Teacher: </b> </div> <div class="teacher"><?php the_field('teacher'); ?></div> <div class="cfee"><b>Class Fee: </b></div> <div class="fee"><?php the_field('fee'); ?></div> <div class="description"><?php the_field('description'); ?></div> <div class="cemail"><b>Email: </b> </div> <div class="email"><?php the_field('cemail'); ?></div> <div class="caddress"><b>Address: </b> </div> <div class="address"><?php the_field('address'); ?></div> <div class="csite"><b>Website: </b> </div> <div class="cwebsite"><?php the_field('website'); ?></div> <div class="ccontact"> <b>Contact: </b></div> <div class="contactp"><?php the_field('contactp'); ?></div> <div class="cimage"> " /> </div> <div class="imagepos"><?php the_field('page_image_position'); ?>" </div>; <?php }?> I'm still learning. Thanks for your guidance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×