Wordpress 强制发布以选择类别

2 wordpress wordpress-theming

我正在使用 WordPress 帖子来构建帖子。当我没有为帖子选择类别时,是否有任何插件或某些功能会发出警告。每当我发布类别时,我都会很头疼,因为有很多一段时间后要在该类别中发布的帖子看到那些未分类的帖子真是令人头疼。

add_theme_support('menus');
Run Code Online (Sandbox Code Playgroud)

**

**> 上面的代码没什么,因为堆栈溢出不允许我

发布我的问题,因为它说标准低。**

** 提前致谢。希望我能找到一个合适的答案

ans*_*ver 5

哈哈..它太有趣了,但你可以在你的functions.php文件中尝试如下

function force_post_categ_init() 
{
  wp_enqueue_script('jquery');
}
function force_post_categ() 
{
  echo "<script type='text/javascript'>\n";
  echo "
  jQuery('#publish').click(function() 
  {
    var cats = jQuery('[id^=\"taxonomy\"]')
      .find('.selectit')
      .find('input');
    category_selected=false;
    for (counter=0; counter<cats.length; counter++) 
    {
        if (cats.get(counter).checked==true) 
        {
            category_selected=true;
            break;
        }
    }
    if(category_selected==false) 
    {
      alert('You have not selected any category for the post. Please select post category.');
      setTimeout(\"jQuery('#ajax-loading').css('visibility', 'hidden');\", 100);
      jQuery('[id^=\"taxonomy\"]').find('.tabs-panel').css('background', '#F96');
      setTimeout(\"jQuery('#publish').removeClass('button-primary-disabled');\", 100);
      return false;
    }
  });
  ";
   echo "</script>\n";
}
add_action('admin_init', 'force_post_categ_init');
add_action('edit_form_advanced', 'force_post_categ');
Run Code Online (Sandbox Code Playgroud)

注意:-必须启用 javascript 才能运行它