How to Highlight current category on category and single page template?

You can do something like <?php $current_category = get_the_category(); /* $current_category[0]->ID is holding the current category now. If there are more than 1 categories for the post you should iterate through all of them and check if the current category you’re displaying is in there */ $cats = get_categories(‘hide_empty=0&child_of=2&orderby=count&number=99&order=asc’); foreach ((array)$cats as $cat) { $catdesc … Read more

Changing the display of the themename_posted_on() function

This question is entirely Theme-dependent. The function will be defined in functions.php, or in a file included in functions.php. Based on the function name, I’m going to take a guess that the Theme in question is derived from Underscores, in which case the function will be defined in /inc/template-tags.php.

Custom Post Type Specific Post Template

For some reason wordpress don’t honor Template_Hierarchy. The best way to get around this problem is to “force” wordpress to use the custom single.php template that you created. To accomplish that, add the following function underneath your CPT. /* Information Posts Template selection – a single.php just for our wrestler_profiles */ function pietergoosen_info_template_include( $original_template ) … Read more

is_single(); Question

You should have a look at using conditional tags in wordpress. is_single() is the conditional tag for a single page, ie single.php. For homepage, is_home() or is_front_page() should be use, depending on whether a front page is set in settings or not.

How to check if a post is in categories x,y,z inludint their subcategories

post_is_in_descendant_category is not a WP function. If you don’t define it, it doesn’t exist. I think that you have read the docs for in_category() function and have taken post_is_in_descendant_category from the example without read it completely. Add this code to functions.php or in a plugin: if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( … Read more

Insert a field with PREG_REPLACE – strange behaviour

You need to use get_field function here instead of the_field. function wrapImagesInDiv($content) { if ( in_category( ‘projects’ ) ) { $pattern = ‘/(<img[^>]*class=\”([^>]*?)\”[^>]*>)/i’; $replacement=” <div class=”owl-wrapper”> <div class=”owl-item $2″> “.get_field(‘description’).’ $1 </div> </div>’; $content = preg_replace($pattern, $replacement, $content); } return $content; } add_filter(‘the_content’, ‘wrapImagesInDiv’); Function get_field returns the value but the_field prints the value.

How to reorder the content of the single post?

try this in functions.php function author_after_content($content) { if ( is_singular(‘post’) ) { $content .= “<p>بقلم : ” . the_author() . “</p>”; } return $content; } add_filter(‘the_content’, ‘author_after_content’, 20);

How to get nav to show current_page_parent class when on regular post (not blog), differentiated by category

I found the correct syntax is: if ( is_single() && in_category ( ‘5’ ) ) { However, I solved the problem using this code: //add category classes to single.php add_filter(‘body_class’,’add_category_to_single’); function add_category_to_single($classes, $class) { if (is_single() ) { global $post; foreach((get_the_category($post->ID)) as $category) { // add category slug to the $classes array $classes[] = $category->category_nicename; … Read more

Integrating WordPress with Your Website

If I understand your needs correctly, you would like to have your /blog page and post items aggregated and driven by WordPress without exposing the user to anything WordPress. To solve the problem with “wordpress” being in the url, you should actually be putting the entire contents of the WordPress install into the website.tld/blog directory. … Read more