{"id":165,"date":"2020-05-21T10:33:16","date_gmt":"2020-05-21T02:33:16","guid":{"rendered":"https:\/\/www.cuishaofeng.com\/?p=165"},"modified":"2024-10-22T14:45:52","modified_gmt":"2024-10-22T06:45:52","slug":"%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0wordpress%e6%b7%bb%e5%8a%a0%e9%a6%96%e9%a1%b5%e6%bb%9a%e5%8a%a8%e5%85%ac%e5%91%8a%e6%a0%8f","status":"publish","type":"post","link":"https:\/\/www.cuishaofeng.com\/?p=165","title":{"rendered":"\u4ee3\u7801\u5b9e\u73b0WordPress\u6dfb\u52a0\u9996\u9875\u6eda\u52a8\u516c\u544a\u680f"},"content":{"rendered":"<div id=\"core-ai-summary-tool\"><\/div>\n<p>\u56e0\u4e3a\u7f51\u4e0a\u6d41\u4f20\u5f88\u591a\u7eaf\u4ee3\u7801\u7ed9 WordPress \u6dfb\u52a0\u4e00\u4e9b\u6587\u5b57\uff0c\u8fd9\u91cc\u6211\u5c31\u4e0d\u591a\u8bc4\u4ef7\u4e86\uff0c\u4e0d\u8fc7\u786e\u5b9e\u7ed9\u4e86\u6211\u4e00\u4e9b\u60f3\u6cd5\uff0c\u5177\u4f53\u5b9e\u65bd\u770b\u4e00\u4e0b\u8bf4\u660e\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6dfb\u52a0\u516c\u544a\u6587\u7ae0\u7c7b\u578b<\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u6ce8\u518c\u4e00\u4e2a\u516c\u544a\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5305\u62ec\u516c\u544a\u7684\u65b0\u5efa\uff0c\u6dfb\u52a0\uff0c\u7f16\u8f91\u4e0e\u5220\u9664\u3002\u5728 functions.php \u7684\u540c\u7ea7\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a gonggao.php \uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nfunction post_type_bulletin() {\n register_post_type(\n 'bulletin',\n array( 'public' => true,\n        'publicly_queryable' => true,\n        'hierarchical' => false,\n        'labels'=>array(\n        'name' => _x('\u516c\u544a', 'post type general name'),\n        'singular_name' => _x('\u516c\u544a', 'post type singular name'),\n        'add_new' => _x('\u6dfb\u52a0\u65b0\u516c\u544a', '\u516c\u544a'),\n        'add_new_item' => __('\u6dfb\u52a0\u65b0\u516c\u544a'),\n        'edit_item' => __('\u7f16\u8f91\u516c\u544a'),\n        'new_item' => __('\u65b0\u7684\u516c\u544a'),\n        'view_item' => __('\u9884\u89c8\u516c\u544a'),\n        'search_items' => __('\u641c\u7d22\u516c\u544a'),\n        'not_found' =>  __('\u60a8\u8fd8\u6ca1\u6709\u53d1\u5e03\u516c\u544a'),\n        'not_found_in_trash' => __('\u56de\u6536\u7ad9\u4e2d\u6ca1\u6709\u516c\u544a'),\n        'parent_item_colon' => ''\n        ),\n        'show_ui' => true,\n        'menu_position'=>5,\n        'supports' => array(\n        'title',\n        'author',\n        'excerpt',\n        'thumbnail',\n        'trackbacks',\n        'editor',\n        'comments',\n        'custom-fields',\n        'revisions' ) ,\n        'show_in_nav_menus' => true ,\n        'menu_icon' => 'dashicons-megaphone',\n        'taxonomies' => array(\n        'menutype',\n        'post_tag')\n )\n );\n}\nadd_action('init', 'post_type_bulletin');\n \nfunction create_genre_taxonomy() {\n $labels = array(\n 'name' => _x( '\u516c\u544a\u5206\u7c7b', 'taxonomy general name' ),\n 'singular_name' => _x( 'genre', 'taxonomy singular name' ),\n 'search_items' =>  __( '\u641c\u7d22\u5206\u7c7b' ),\n 'all_items' => __( '\u5168\u90e8\u5206\u7c7b' ),\n 'parent_item' => __( '\u7236\u7ea7\u5206\u7c7b\u76ee\u5f55' ),\n 'parent_item_colon' => __( '\u7236\u7ea7\u5206\u7c7b\u76ee\u5f55:' ),\n 'edit_item' => __( '\u7f16\u8f91\u516c\u544a\u5206\u7c7b' ),\n 'update_item' => __( '\u66f4\u65b0' ),\n 'add_new_item' => __( '\u6dfb\u52a0\u65b0\u516c\u544a\u5206\u7c7b' ),\n 'new_item_name' => __( 'New Genre Name' ),\n );\n register_taxonomy('genre',array('bulletin'), array(\n 'hierarchical' => true,\n 'labels' => $labels,\n 'show_ui' => true,\n 'query_var' => true,\n 'rewrite' => array( 'slug' => 'genre' ),\n ));\n}\nadd_action( 'init', 'create_genre_taxonomy', 0 );<\/code><\/pre>\n\n\n\n<p>\u5728 functions.php \u4e2d\u5f15\u7528\u8be5\u516c\u544a\u7684 gonggao.php \u6587\u4ef6\uff0c\u5728 functions.php \u7684\u5e95\u90e8\u52a0\u4e0a\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include (\"gonggao.php\");<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\uff0c\u518d\u767b\u5f55\u5230 wordpress \u7f51\u7ad9\u7684\u540e\u53f0\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u5728\u6587\u7ae0\u7684\u4e0b\u9762\u591a\u4e86\u4e00\u4e2a\u516c\u544a\u6807\u7b7e\u3002<br>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'menu_icon' => 'dashicons-megaphone',<\/code><\/pre>\n\n\n\n<p>\u5c31\u662f\u6211\u4eec\u8bbe\u5b9a\u7684 Dashicons \u56fe\u6807\uff0c\u6548\u679c\u5982\u4e0b\u56fe\u3002\u5982\u679c\u53bb\u6389\u8fd9\u884c\u7684\u8bdd\uff0c\u56fe\u6807\u9ed8\u8ba4\u548c\u6587\u7ae0\u7684\u56fe\u6807\u4e00\u6837\u3002\u6b64\u5904\u7701\u7565\u56fe<\/p>\n\n\n\n<p>\u60f3\u83b7\u53d6\u5176\u4ed6\u7684 Dashicons \u56fe\u6807\uff1f\u70b9\u51fb\u524d\u5f80&nbsp;<a href=\"https:\/\/www.wenzika.com\/go\/?url=https:\/\/developer.wordpress.org\/resource\/dashicons\/#editor-customchar\" target=\"_blank\" rel=\"noreferrer noopener\">Dashicons \u4e3b\u9875<\/a>\uff0c\u9009\u53d6\u81ea\u5df1\u559c\u6b22\u7684\u56fe\u6807\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6dfb\u52a0\u516c\u544a\u6837\u5f0f<\/h3>\n\n\n\n<p>\u5c06\u4e0b\u9762\u7684\u516c\u544a\u5185\u5bb9\u4ee3\u7801\u653e\u5728 index.php \u81ea\u5df1\u60f3\u8981\u663e\u793a\u7684\u4f4d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div id=\"site-gonggao\">\n&lt;div class=\"site-gonggao-div\">&lt;i class=\"fa fa-volume-up\">&lt;\/i> &lt;\/div>\n &lt;div id=\"site-gonggao-div2\" class=\"sitediv\">\n    &lt;ul class=\"list\" id=\"siteul\">\n    &lt;?php $loop = new WP_Query( array( 'post_type' => 'bulletin', 'posts_per_page' => 3 ) );\n          while ( $loop->have_posts() ) : $loop->the_post();\n     ?>\n      &lt;li>&lt;?php mb_strimwidth(the_content(), 0, 70, '\u2026'); ?>&lt;\/li>\n      &lt;?php endwhile; wp_reset_query(); ?>\n      &lt;\/ul>\n &lt;\/div>\n&lt;\/div><\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d 3 \u4ee3\u8868\u6709 3 \u6761\u516c\u544a\uff0c 70 \u5219\u8868\u793a\u6bcf\u4e2a\u516c\u544a\u663e\u793a 70 \u4e2a\u5b57\u7b26\u3002\u8fd9\u4e2a\u53ef\u4ee5\u6839\u636e\u4f60\u81ea\u5df1\u7684\u60c5\u51b5\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6dfb\u52a0 css \u4ee3\u7801<\/h3>\n\n\n\n<p>\u5c06\u4e0b\u9762\u4ee3\u7801\u590d\u5236\u5230 main.css \u6587\u4ef6\u5f53\u4e2d\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div#site-gonggao {\n    line-height: 25px;\n    height: 30px;\n    background-color: #FFF;\n    padding-left: 10px;\n    color: #666;\n    -webkit-box-shadow: 0 5px 5px #D3D3D3;\n    box-shadow: 0 5px 5px #D3D3D3;\n}\n \n#site-gonggao .list {\n    padding-left: 5px;\n}\n \n.site-gonggao-div {\n    float: left;\n}\n \n.fa-volume-up:before {\n    content: \"\\f028\";\n    color: #428bca;\n}\n \n#site-gonggao a {\n    color: #1663B7;\n}\n \n#site-gonggao a:hover {\n    color: #09F;\n}\n \n#site-gonggao-div2 {\n    overflow: hidden;\n    height: 30px;\n}\n \n#site-gonggao-div2 .list li {\n    height: 30px;\n    line-height: 30px;\n    overflow: hidden;\n}\n \n#site-gonggao-div2 .list li p {\n    display: inline;\n    overflow: hidden;\n    white-space: nowrap;\n    text-overflow: ellipsis;\n}<\/code><\/pre>\n\n\n\n<p>\u5f53\u7136\u8fd9\u4e2a\u6837\u5f0f\u4e0d\u662f\u5f88\u597d\u770b\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u5df1\u8bbe\u7f6e\uff01<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u6dfb\u52a0\u6eda\u52a8\u516c\u544a js \u4ee3\u7801<\/h3>\n\n\n\n<p>\u6dfb\u52a0\u516c\u544a\u7684\u6eda\u52a8\u4ee3\u7801\uff0c\u9700\u8981 jQuery \u5e93\uff0c\u5f53\u7136 DUX \u4e3b\u9898\u662f\u5df2\u7ecf\u52a0\u8f7d\u4e86\u7684\uff0c\u76f4\u63a5\u5c06\u4e0b\u9762\u4ee3\u7801\u590d\u5236\u5230 header.php \u4e2d\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function autoScroll(obj){  \nvar aa=document.getElementById(\"siteul\").getElementsByTagName(\"li\").length;\nif(aa!==1){\n    jQuery(obj).find(\".list\").animate({  \n          marginTop : \"-30px\"  \n      },500,function(){  \n      jQuery(this).css({marginTop : \"0px\"}).find(\"li:first\").appendTo(this);  \n      })  \n      };\n      }\n   $(function(){   \n       setInterval('autoScroll(\".sitediv\")',4000)  \n     })  ;<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\uff0c\u7b2c 4 \u884c\u7684 \u201c.list\u201d \u662f\u8c03\u7528\u4ee3\u7801\u4e2d\uff0cul \u6807\u7b7e\u7684 class \u6837\u5f0f\uff1b\u7b2c 12 \u884c\u7684 \u201c.sitediv\u201d \u662f\u5305\u88f9 ul \u7684 div \u6807\u7b7e\u7684 class \u6837\u5f0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u540e\u8bb0<\/h3>\n\n\n\n<p>\u4ee3\u7801\u67d0\u4e9b\u65b9\u9762\u8fd8\u662f\u6709\u4e9b\u6b20\u7f3a\u7684\uff0c\u4e0d\u8fc7\u8fd9\u4e2a\u7248\u672c\u7684\u6eda\u52a8\u516c\u544a\u680f\u786e\u5b9e\u8981\u663e\u5f97\u6b63\u5f0f\u4e00\u4e9b\uff01\u53ea\u662f\u8fd9\u4e2a\u7248\u672c\u8fd8\u6709\u4e9b\u4e0d\u5b8c\u7f8e\uff0c\u6bd4\u5982\u7f3a\u5c11\u4e00\u4e2a\u6eda\u52a8\u516c\u544a\u7684\u5f00\u5173\uff0c\u6bd4\u5982\uff0c\u60f3\u76f4\u63a5\u5173\u95ed\u516c\u544a\u8fd9\u4e2a\u529f\u80fd\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u529f\u80fd\u6211\u4e5f\u6298\u817e\u4e86\u5f88\u4e45\uff0c\u53ef\u60dc\u7684\u662f\u6709\u4e9b bug \uff0c\u5c31\u76f4\u63a5\u653e\u5f03\u4e86\uff0c\u5982\u679c\u6709\u5927\u795e\u5199\u51fa\u6765\u4e86\uff0c\u6b22\u8fce\u5206\u4eab\u4f60\u7684\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u7f51\u4e0a\u6d41\u4f20\u5f88\u591a\u7eaf\u4ee3\u7801\u7ed9 WordPress \u6dfb\u52a0\u4e00\u4e9b\u6587\u5b57\uff0c\u8fd9\u91cc\u6211\u5c31\u4e0d\u591a\u8bc4\u4ef7\u4e86\uff0c\u4e0d\u8fc7\u786e\u5b9e\u7ed9\u4e86\u6211\u4e00\u4e9b\u60f3\u6cd5\uff0c\u5177\u4f53\u5b9e\u65bd\u770b\u4e00\u4e0b\u8bf4\u660e\uff1a 1. \u6dfb\u52a0\u516c\u544a\u6587\u7ae0\u7c7b\u578b \u9996\u5148\uff0c\u6ce8\u518c\u4e00\u4e2a\u516c\u544a\u7684\u6587\u7ae0\u7c7b\u578b\uff0c\u5305\u62ec\u516c\u544a\u7684\u65b0\u5efa\uff0c\u6dfb\u52a0\uff0c\u7f16\u8f91\u4e0e\u5220\u9664\u3002\u5728 functions.p&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[104],"topic":[],"_links":{"self":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/165"}],"collection":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":1,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.cuishaofeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}