How to get posts by category at /%category%/ url?

Is the archive.php correct template for that? archive.php is the most common file to load any kind of archive posts. But anytime the user loads a category archive page, WordPress template system looks for files in this order: category-slug.php → category-id.php → category.php → archive.php → index.php If you want to create a specific template … Read more

Get custom title if category

change this one line in your code: <h1 class=”article-title entry-title”>How To <?php the_title(); ?> Free</h1> to: CORRECTION: <h1 class=”article-title entry-title”><?php if( in_category( array(‘news’) ) ) { the_title(); } else { ?> How To <?php the_title(); ?> Free<?php } ?></h1> https://developer.wordpress.org/reference/functions/in_category/

How can you access category information from a theme?

Show the category title, description and a url to it’s archive by using it’s category ID: Get category title: get_the_category_by_ID() Get category description (ID optional): category_description() Get category archive URL: get_category_link() Get the Ids of the oldest and newest post in that category: // Get oldest post ID $posts = get_posts( array( ‘category’ => 1, … Read more

Is it possible to have a template that works on multiple categories where the link address contains the specific category?

Why not using a meta field ? That way you can determine which template to use for specific category template. In your loop just get the current category that you are trying to load: if( have_posts() ) { while( have_posts() ) { the_post(); $meta_value = get_post_meta( get_the_ID() , ‘meta-field’, true ); if($meta_value == ‘template1’) { … Read more

Add custom code at start and end of all posts in a category

You can edit the template associated with your Category template in your theme. If you don’t own the theme, you can make a Child theme of it to modify things. For example, in my local WordPress dev environment, I have the theme TwentyTwenty active, and the template responsible for displaying is the index.php (typically it’s … Read more

Add theme-color meta tag to head?

The parser has the problem with usage of “, because it is not possible what is for PHP or for the syntax to echo. So change them like. $post_category = get_the_category()[‘0’]->term_id; if ($post_category == 75) { echo ‘<meta name=”theme-color” content=”#B7E0D2″>’; } else { echo'<meta name=”theme-color” content=”#000000″>’; } In the context of your hint to see … Read more

Hide specific category from wp_list_categories

You can use the exclude parameter: ‘exclude’ (array|string) Array or comma/space-separated string of term IDs to exclude. If $hierarchical is true, descendants of $exclude terms will also be excluded; see $exclude_tree. See get_terms(). So with your $args: $args = array( ‘hide_empty’ => true, ‘title_li’ => ”, ‘show_count’ => 0, ‘echo’ => 0, // Excludes specific … Read more