{"id":60,"date":"2013-12-22T17:00:33","date_gmt":"2013-12-22T09:00:33","guid":{"rendered":"http:\/\/web.jofar.cn\/?p=60"},"modified":"2013-12-22T17:00:33","modified_gmt":"2013-12-22T09:00:33","slug":"drupal%e4%b8%adtemplate-php%e7%9a%84%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/web.jofar.cn\/?p=60","title":{"rendered":"Drupal\u4e2dtemplate.php\u7684\u4f5c\u7528"},"content":{"rendered":"<p>\u4f60\u53ef\u80fd\u77e5\u9053\u5728drupal\u7684\u6a21\u677f\u4e2d\uff08\u6bd4\u5982node.tpl.php\uff09\u9690\u85cf\u4e86\u5f88\u591a\u4fe1\u606f\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>&lt;div&gt;&lt;?php print $links; ?&gt;&lt;\/div&gt;<\/p>\n<p>\u5982\u679c\u4f60\u662f\u4e2a\u8bbe\u8ba1\u4eba\u5458\u6216\u8005drupal\u7684\u4f7f\u7528\u8005\uff0c\u4f60\u53ef\u80fd\u4e0d\u77e5\u9053$links\u4e2d\u90fd\u5305\u542b\u4e86\u54ea\u4e9b\u4fe1\u606f\uff0cdeve\u6a21\u5757\u63d0\u4f9b\u4e00\u4e2a\u51fd\u6570dsm\uff08\uff09\u53ef\u4ee5\u5f88\u8f7b\u677e\u7684\u67e5\u770b$links\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>&lt;?php dsm(&#8216;$links&#8217;); ?&gt;<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u529e\u6cd5\uff0c\u53ef\u662f\u867d\u7136\u77e5\u9053\u4e86$links\u7684\u4fe1\u606f\uff0c\u5982\u679c\u8981\u4fee\u6539$links\u53c8\u8981\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p><input type=\"image\" height=\"226\" src=\"http:\/\/yp.oss.org.cn\/images\/userimages\/links-link.png\" width=\"867\" \/><br \/>\n\u6bd4\u5982\u6709\u4e00\u4e2a\u6587\u7ae0\uff0c\u540e\u9762\u8ddf\u4e86\u4e00\u4e9b\u94fe\u63a5\uff08$links\uff09\uff0c\u5305\u62ec\u8bc4\u8bba\u6570\u3001\u5168\u90e8\u9605\u8bfb\u548c\u9605\u8bfb\u6b21\u6570\u3002\u5982\u679c\u4f60\u60f3\u4fee\u6539\u94fe\u63a5\u7684\u683c\u5f0f\u6216\u6837\u5b50\uff0c\u53ea\u8981\u91cd\u5199<a href=\"http:\/\/api.drupal.org\/api\/function\/theme_links\/6\" rel=\"noreferrer\">theme_links()<\/a>\u8fd9\u4e2a\u51fd\u6570\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f46\u662f\u5982\u679c\u4f60\u60f3\u6539\u53d8\u8bc4\u8bba\u6570\u7684\u4f4d\u7f6e\uff0c\u6bd4\u5982\uff1a<\/p>\n<p><input type=\"image\" height=\"234\" src=\"http:\/\/yp.oss.org.cn\/images\/userimages\/3.PNG\" width=\"857\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u8981\u628a\u8bc4\u8bba\u6570\u7684\u94fe\u63a5\u653e\u5230\u65e5\u671f\u540e\u9762\u7136\u540e\u5220\u9664\u5168\u90e8\u9605\u8bfb\u7684\u94fe\u63a5\uff0c\u90a3\u6211\u4eec\u53c8\u8981\u600e\u4e48\u505a\u5462?\u5148\u6765\u770b\u770bnode.tpl.php\u7684\u4ee3\u7801\uff1a<\/p>\n<p>&lt;h1&gt;&lt;?php print $title;? ?&gt;&lt;\/h1&gt;<br \/>\n&lt;div&gt;&lt;?php print $name .&#8221; | &#8221; . $date; ?&gt; &lt;\/div&gt;<br \/>\n&lt;p&gt;&lt;?php print $content ?&gt;&lt;\/p&gt;<br \/>\n&lt;div&gt;&lt;?php?<strong>print $links<\/strong>; ?&gt;&lt;\/div&gt;<\/p>\n<p>\u5982\u679c\u8981\u505a\u5230\u6211\u4eec\u60f3\u8981\u7684\u5fc5\u987b\u8981\u62c6\u5206$links\uff0c\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>&lt;h1&gt;&lt;?php print $title;? ?&gt;&lt;\/h1&gt;<br \/>\n&lt;div&gt;&lt;?php print $name .&#8221; | &#8221; . $date . &#8221; | &#8221; .?<strong>$number_of_comments<\/strong>; ?&gt;&lt;\/div&gt;<br \/>\n&lt;p&gt;&lt;?php print $content ?&gt;&lt;\/p&gt;<br \/>\n&lt;div&gt;&lt;?php?<strong>print $read_more<\/strong>; ?&gt;&lt;\/div&gt;? \/\/\u8fd9\u884c\u4ee3\u7801\u5c06\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u9700\u6c42\u662f\u5220\u9664\u5168\u90e8\u9605\u8bfb\u7684\u94fe\u63a5\u3002<\/p>\n<p>\u4f46\u662f\u76ee\u524d\u6211\u4eec\u8fd8\u6ca1\u6709$read_more\u548c$number_of_comments\u53d8\u91cf\uff0c\u6240\u4ee5\u5148\u770b\u770b$links\u7684\u7ed3\u6784\uff1a<br \/>\n&lt;?php dsm($node-&gt;links); ?&gt;<\/p>\n<p><input type=\"image\" height=\"451\" src=\"http:\/\/yp.oss.org.cn\/images\/userimages\/links-template.png\" width=\"832\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u53ef\u4ee5\u770b\u51facomment_comments\u5c31\u662f\u8bc4\u8bba\u6570\u7684\u94fe\u63a5\uff0c\u6240\u4ee5\u6211\u4eec\u76f4\u63a5\u5c06comment_comments\u653e\u5230\u65e5\u671f\u7684\u540e\u9762<\/p>\n<p>&lt;h1&gt;&lt;?php print $title;? ?&gt;&lt;\/h1&gt;<br \/>\n&lt;div&gt;&lt;?php print $name .&#8221; | &#8221; . $date . &#8221; | &#8221; .?<strong>$vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;title&#8217;];?<\/strong>?&gt; &lt;\/div&gt;<br \/>\n&lt;p&gt;&lt;?php print $content ?&gt;&lt;\/p&gt;<\/p>\n<p>\u4f46\u662f\u8fd9\u79cd\u5199\u6cd5\u662f\u9519\u8bef\u7684\uff0c\u6211\u4eec\u9700\u8981\u7684\u662f\u94fe\u63a5\uff0c\u6240\u4ee5\u5c31\u8981<a href=\"http:\/\/api.drupal.org\/api\/function\/l\/6\" rel=\"noreferrer\">l()\u51fd\u6570<\/a>\u3002<\/p>\n<p>&lt;?php<\/p>\n<p>l(<br \/>\n$vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;title&#8217;],<br \/>\n$vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;href&#8217;],<br \/>\narray(&#8216;attributes&#8217; =&gt; array(&#8216;class&#8217; =&gt; &#8216;comment&#8217;,&#8217;title&#8217;?=&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;attributes&#8217;][&#8216;title&#8217;] ))<br \/>\n);<br \/>\n?&gt;<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u7684node.tpl.php\u5c31\u662f\uff1a<\/p>\n<p>&lt;?php<br \/>\n\/\/link comment<br \/>\n$<strong>link_comment?<\/strong>=? l($vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;title&#8217;],?$vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;href&#8217;], array(&#8216;attributes&#8217; =&gt; array(&#8216;class&#8217; =&gt; &#8216;comment&#8217;,&#8217;title&#8217; =&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;attributes&#8217;][&#8216;title&#8217;] )));<\/p>\n<p>\/\/and lets create the read more links<br \/>\n$<strong>link_read_more?<\/strong>=? l($vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;title&#8217;], $vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;href&#8217;],<br \/>\narray(&#8216;attributes&#8217; =&gt; array(&#8216;class&#8217; =&gt; &#8216;read-more&#8217;,&#8217;title&#8217; =&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;attributes&#8217;][&#8216;title&#8217;] )));<br \/>\n?&gt;<\/p>\n<p>&lt;h1&gt;&lt;?php print $title;? ?&gt;&lt;\/h1&gt;<br \/>\n&lt;div&gt;&lt;?php print $name .&#8221; | &#8221; . $date . &#8221; | &#8221; .?<strong>$link_comment<\/strong>; ?&gt; &lt;\/div&gt;<br \/>\n&lt;p&gt;&lt;?php print $content ?&gt;&lt;\/p&gt;<br \/>\n&lt;div&gt;&lt;?php print?<strong>$link_read_more<\/strong>; ?&gt;&lt;\/div&gt;<\/p>\n<p>\u867d\u7136\u5b9e\u73b0\u4e86\u6211\u4eec\u60f3\u8981\u7684\u529f\u80fd\uff0c\u4f46\u662f\u4ee3\u7801\u770b\u8d77\u6765\u5f88\u4e11\u964b\u3002\u5982\u679c\u6211\u4eec\u6709\u5f88\u591a\u7684node.tpl.php\uff08node-blog.tpl.php, node-page.tpl.php, node-news.tpl.php\uff09\u6211\u4eec\u8fd8\u9700\u8981\u6bcf\u4e00\u4e2a\u9875\u9762\u90fd\u624b\u52a8\u4fee\u6539\uff0c\u8fd9\u662f\u7f16\u7a0b\u7684\u5927\u5fcc\u3002<\/p>\n<p>\u800ctemplate.php\u53ef\u4ee5\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u628a\u6240\u6709\u7684\u903b\u8f91\u4ee3\u7801\u90fd\u653e\u5230\u8fd9\u4e2a\u6587\u4ef6\u91cc\uff0c\u4ece\u800c\u4fdd\u8bc1\u4e86node.tpl.php\u5e72\u51c0\u3002\u5982\u679c\u6ca1\u6709template.php\u53ef\u4ee5\u5728\u4e3b\u9898\uff08theme\uff09\u6587\u4ef6\u5939\u4e0b\u65b0\u5efa\u8fd9\u4e2a\u6587\u4ef6\uff0c\u66f4\u591a\u4fe1\u606f\u8bf7\u53c2\u8003<a href=\"http:\/\/drupal.org\/node\/11811\" rel=\"noreferrer\">http:\/\/drupal.org\/node\/11811<\/a><\/p>\n<p>&lt;?php<br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n\/\/file?<strong>template.php<\/strong><br \/>\n\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nfunction?<strong>THEMENAME_preprocess_node<\/strong>(&amp;$vars) {<br \/>\n\/\/comments<br \/>\nif($vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;]){<br \/>\n<strong>$vars[&#8216;link_comment&#8217;]?<\/strong>=? l($vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;title&#8217;], $vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;href&#8217;],<br \/>\narray(<br \/>\n&#8216;attributes&#8217; =&gt; array(&#8216;class&#8217; =&gt; &#8216;comment&#8217;, &#8216;title&#8217; =&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;attributes&#8217;][&#8216;title&#8217;]),<br \/>\n&#8216;fragment&#8217; =&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;comment_comments&#8217;][&#8216;fragment&#8217;]<br \/>\n)<br \/>\n);<br \/>\n}<br \/>\nif($vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;]){<br \/>\n<strong>$vars[&#8216;link_read_more&#8217;]<\/strong>?=? l($vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;title&#8217;], $vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;href&#8217;], array(&#8216;attributes&#8217; =&gt; array(&#8216;class&#8217; =&gt; &#8216;read-more&#8217;,&#8217;title&#8217; =&gt; $vars[&#8216;node&#8217;]-&gt;links[&#8216;node_read_more&#8217;][&#8216;attributes&#8217;][&#8216;title&#8217;] )));<br \/>\n}<\/p>\n<p>?&gt;<\/p>\n<p>THEMENAME_preprocess_node\u662f\u4f1a\u5728node.tpl.php\u4e4b\u524d\u8fd0\u884c\u7684\u51fd\u6570\uff0c\u7c7b\u4f3c\u7684\u8fd8\u6709THEMENAME_preprocess_page\u3001THEMENAME_preprocess_block\u7b49\u7b49\u3002<\/p>\n<p>node.tpl.php\u4e0d\u53d8\uff1a<\/p>\n<p>&lt;h1&gt;&lt;?php print $title;? ?&gt;&lt;\/h1&gt;<br \/>\n&lt;div&gt;&lt;?php print $name .&#8221; | &#8221; . $date . &#8221; | &#8221; .?<strong>$link_comment<\/strong>; ?&gt; &lt;\/div&gt;<br \/>\n&lt;p&gt;&lt;?php print $content ?&gt;&lt;\/p&gt;<br \/>\n&lt;div&gt;&lt;?php print?<strong>$link_read_more<\/strong>; ?&gt;&lt;\/div&gt;<\/p>\n<p>\u8fd9\u6837\u770b\u8d77\u6765\u662f\u4e0d\u662f\u66f4\u597d\u4e00\u4e9b\u5462\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u53ef\u80fd\u77e5\u9053\u5728drupal\u7684\u6a21\u677f\u4e2d\uff08\u6bd4\u5982node.tpl.php\uff09\u9690\u85cf\u4e86\u5f88\u591a\u4fe1\u606f\uff0c\u6bd4\u5982\uff1a &lt;div&gt;\u2026 <span class=\"read-more\"><a href=\"https:\/\/web.jofar.cn\/?p=60\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4],"tags":[],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-drupal","category-design-pursuit"],"_links":{"self":[{"href":"https:\/\/web.jofar.cn\/index.php?rest_route=\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/web.jofar.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.jofar.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.jofar.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/web.jofar.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=60"}],"version-history":[{"count":0,"href":"https:\/\/web.jofar.cn\/index.php?rest_route=\/wp\/v2\/posts\/60\/revisions"}],"wp:attachment":[{"href":"https:\/\/web.jofar.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.jofar.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.jofar.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}