How to display a linked category name with get_the_category

get_the_category() returns the array of WP_Term objects. So, // get all categories objects $categories = get_the_category(); // get the first category name if ( ! empty( $categories ) ) { $category = $categories[0]->name; } $output .= ‘<li><a href=”https://wordpress.stackexchange.com/questions/293636/” . get_the_permalink() . “https://wordpress.stackexchange.com/questions/293636/”>’; $output .= get_the_title() . ‘</a> ‘; $output .= $category .”https://wordpress.stackexchange.com/questions/293636/”; $output .= get_the_time(‘d … Read more

How to get child category list post in one template?

get the child categories, using get_categories(); then loop through them with a foreach loop, using WP_Query() : <?php $cats = get_categories(‘child_of=”.get_query_var(“cat’)); foreach ($cats as $cat) : $args = array( ‘posts_per_page’ => 3, // max number of post per category ‘category__in’ => array($cat->term_id) ); $my_query = new WP_Query($args); if ($my_query->have_posts()) : echo ‘<h3>’.$cat->name.'</h3>’; while ($my_query->have_posts()) : … Read more

Display post content from category name using ajax

add_action( ‘wp_ajax_nopriv_load-filter’, ‘prefix_load_cat_posts’ ); add_action( ‘wp_ajax_load-filter’, ‘prefix_load_cat_posts’ ); function prefix_load_cat_posts () { global $post; $cat_id = $_POST[ ‘cat’ ]; $args = array ( ‘cat’ => $cat_id, ‘posts_per_page’ => 3, ‘order’ => ‘ASC’ ); $cat_query = new WP_Query($args); if($cat_query->have_posts()) : while($cat_query->have_posts()) : $cat_query->the_post(); $response=”<div class=”the-post”>”; $response .= ‘<h1 class=”the-title”>’; $response .= ‘<a href=”#”>’. get_the_title() .'</a>’; $response … Read more

Javascript code for Category

Write this in your theme’s functions.php file function category_enqueue_script() { $cat_education_id = ‘xx’; // category id for “education” $cat_dog_id = ‘yy’; // category id for “dog” if ( is_category() && ( is_category( $cat_education_id ) || is_category( $cat_dog_id ) ) ) { wp_enqueue_script( ‘my-js’, ‘filename.js’, false ); } } add_action( ‘wp_enqueue_scripts’, ‘category_enqueue_script’ );

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