Rewrite rule page url with category

Just of the top of my head, something along this way might work: function wpse178647_rewrite() { add_rewrite_rule( ‘^([^/]+)/([^/]+)/?$’, ” ‘index.php?category_name=$matches[1]&pagename=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘wpse178647_rewrite’ ); Completely and utterly untested.

What’s the URL for a category archive?

There is no date-based archive for a category. The /category/[slug]/ pages are already “archives”, in that they display old posts over different pages. The different pages can be accessed by adding page/2/, page/3/, … to the URL. The template tags to add these links are next_posts_link() and previous_posts_link(). If you want to add a date-based … Read more

How can I make post fields required in WordPress?

Fairly simple using jQuery and global $typenow ex: add_action(‘admin_print_scripts-post.php’, ‘my_publish_admin_hook’); add_action(‘admin_print_scripts-post-new.php’, ‘my_publish_admin_hook’); function my_publish_admin_hook(){ global $typenow; if (in_array($typenow, array(‘post’,’page’,’mm_photo ‘))){ ?> <script language=”javascript” type=”text/javascript”> jQuery(document).ready(function() { jQuery(‘#post’).submit(function() { if (jQuery(“#set-post-thumbnail”).find(‘img’).size() > 0) { jQuery(‘#ajax-loading’).hide(); jQuery(‘#publish’).removeClass(‘button-primary-disabled’); return true; }else{ alert(“please set a featured image!!!”); jQuery(‘#ajax-loading’).hide(); jQuery(‘#publish’).removeClass(‘button-primary-disabled’); return false; } return false; }); }); </script> <?php } … Read more

Get top parent category

get_ancestors() returns an array containing the parents of any given object. This example has two categories. The parent with the id of 447 and the child with a id of 448 and returns the a category hierarchy (with IDs): get_ancestors( 448, ‘category’ ); returns: Array ( [0] => 447 ) get_ancestors Codex Page

How to display only 3 main categories, separated by commas, since they are marked in the post?

It should be enough using a single <span> for all categories and add some logic.: <span><?php $categories = [‘horses’,’dogs’,’birds’]; $string = “”; foreach ($categories as $category){ //iterate over the categories to check if(has_category($category)) $string .= $category.”, “; //if in_category add to the output } $string = trim($string); //remove extra space from end $string = rtrim($string, … Read more