{"id":132,"date":"2009-07-21T07:00:03","date_gmt":"2009-07-21T11:00:03","guid":{"rendered":"http:\/\/awgentry.com\/blog\/?p=132"},"modified":"2009-07-21T07:00:03","modified_gmt":"2009-07-21T11:00:03","slug":"easy-menus-with-php-part-2","status":"publish","type":"post","link":"http:\/\/awgentry.com\/weblog\/easy-menus-with-php-part-2\/","title":{"rendered":"Easy Menus with PHP, Part 2"},"content":{"rendered":"<p><a href=\"http:\/\/awgentry.com\/blog\/?p=120\">Yesterday<\/a> I discussed the limited options for <strong>efficient menu-editing<\/strong> available to beginning Web programmers. As promised, here&#8217;s a tutorial for writing your very own <strong><a href=\"http:\/\/us3.php.net\/include\/\" target=\"_blank\">PHP includes<\/a><\/strong>, a boon to menu-making code monkeys. If you haven&#8217;t already, please check out my <span style=\"text-decoration: underline;\">mini PHP crash course<\/span> before continuing.<\/p>\n<p>Using the <a href=\"http:\/\/us3.php.net\/include\/\"><em>include()<\/em><\/a> statement (and it&#8217;s partner <em><a href=\"http:\/\/us3.php.net\/manual\/en\/function.require.php\">require()<\/a> <\/em>) lets you plop a chunk of PHP code in the middle of your HTML or PHP page, like this:<\/p>\n<p class=\"smallfont\" style=\"margin-bottom: 2px;\"><strong>Code:<\/strong><\/p>\n<pre><strong>&lt;!-- HTML here --&gt;\n&lt;?php\n<\/strong><strong>\/\/ horizontal menu (this is a PHP comment)\n<\/strong><strong>include('menu.php');\u00a0  \/\/ \"include the file 'menu.php' right here in the webpage\"<\/strong><strong>\n?&gt;\n&lt;!-- more HTML --&gt;<\/strong><\/pre>\n<div id=\"attachment_128\" style=\"width: 267px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-128\" class=\"size-full wp-image-128\" title=\"SciTE Screenshot\" src=\"http:\/\/gentry.co\/wp-content\/uploads\/2009\/04\/scite-screenshot.png\" alt=\"SciTE Screenshot: This is a code editor I use. It works for (X)HTML, PHP, and much more.\" width=\"261\" height=\"313\" \/><p id=\"caption-attachment-128\" class=\"wp-caption-text\">SciTE Screenshot: This is a code editor I use. It works for (X)HTML, PHP, and much more.<\/p><\/div>\n<p>Here&#8217;s the gist:<\/p>\n<ul>\n<li><strong>Open a text file<\/strong> or text-based HTML editor such as <a href=\"http:\/\/www.scintilla.org\/SciTE.html\">SciTE<\/a>. You\u00a0 need to be editing the source (as opposed to the page&#8217;s visual content).<\/li>\n<li><strong>Insert the PHP code <\/strong>above into where you want the menu to appear. Note:\n<ul>\n<li> The file can have any name, as well, such as\u00a0 <em>1header.htm<\/em>, as long as you use that filename in the PHP code.<\/li>\n<li>The included file can be another extension, such as <em>menu.htm .<\/em> It just may be easier to make it <em>.PHP<\/em> to start with, in case you want to make yet another include inside of that one.<\/li>\n<li>You can use pretty much as many <em>include<\/em>s and <em>require<\/em>s as you want, though trying to load hundreds could make the system choke. It times out after about 30 seconds, cutting off your webpage at that point.\u00a0 (Don&#8217;t worry, this probably won&#8217;t happen unless you&#8217;re a code monkey like me who wants, say, to display all hundred-plus menu category pages from the local chamber of commerce website, all on one page. Didn&#8217;t work out so well.)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li><strong>Save the file as <\/strong><em><strong>.PHP<\/strong> <\/em>(not .HTM or .HTML).<\/li>\n<li><strong>You&#8217;re all done<\/strong>, lickety-split. Congrats!<\/li>\n<li>Now you just have to <strong>do the same thing with all your webpages<\/strong>.<\/li>\n<\/ul>\n<p>&#8220;What?&#8221; you say. &#8220;I thought you were making it so we didn&#8217;t have to manually update every webpage each time we want to change the menu!&#8221; Yes, but you have to <strong>set the framework first. Just make a plan at the beginning <\/strong>&#8212; ideally before you even begin coding your website &#8212; and it will make your work go much more smoothly. Whenever you want to change the menu, just update <em>menu.php<\/em> and the whole site changes to match. <em>Voila&#8217;!<\/em> Instant webpage-menu-updating goodness.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I discussed the limited options for efficient menu-editing available to beginning Web programmers. As promised, here&#8217;s a tutorial for writing your very own PHP includes, a boon to menu-making code monkeys. If you haven&#8217;t already, please check out my mini PHP crash course before continuing. Using the include() statement (and it&#8217;s partner require() )&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[72,69,73,71],"class_list":["post-132","post","type-post","status-publish","format-standard","hentry","category-geek","tag-code-snippets","tag-menu-creation","tag-php-crash-course","tag-web-programming"],"_links":{"self":[{"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/posts\/132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/comments?post=132"}],"version-history":[{"count":0,"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/posts\/132\/revisions"}],"wp:attachment":[{"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/media?parent=132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/categories?post=132"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/awgentry.com\/weblog\/wp-json\/wp\/v2\/tags?post=132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}