How can I check which archive has referred the single? [closed]

Either use http referer or pass own param with your urls determining referring category. The first option seems better to me. The //check, whether a user does not access a page directly if(isset($_SERVER[‘HTTP_REFERER’])) { //get category object $category = get_category_by_path($_SERVER[‘HTTP_REFERER’], false); //if category URL was passed if(NULL !== $category) echo $category->name; //otherwise get your random … Read more

wp_query issue with post_type = page

If your goal is to load the selected custom template for each page within the loop, then you’re actually pretty close to that. You’re getting the value of _wp_page_template, but then you’re not doing anything with that template, you’re just loading content-page.php for each of those pages with the line get_template_part( ‘content’, ‘page’ );. If … Read more

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.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)