п»ї เรียนรู้ tags ที่ใช้ใน template - ประวัติà¸à¸²à¸£à¸›à¸£à¸±à¸šà¸›à¸£à¸¸à¸‡ http://codex.wordthai.com/index.php?title=%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%A3%E0%B8%B9%E0%B9%89_tags_%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B9%83%E0%B8%99_template&action=history ประวัติà¸à¸²à¸£à¸›à¸£à¸±à¸šà¸›à¸£à¸¸à¸‡à¸‚องหน้านี้ในวิà¸à¸´ th MediaWiki 1.13.2 Thu, 28 Mar 2024 15:02:46 GMT Kazama: สร้างหน้าใหม่: If you take a peek into the <tt>header.php</tt> template file that came with your WordPress Theme, you will notice that where it says "My Bl... http://codex.wordthai.com/index.php?title=%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%A3%E0%B8%B9%E0%B9%89_tags_%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B9%83%E0%B8%99_template&diff=107&oldid=prev <p>สร้างหน้าใหม่: If you take a peek into the &lt;tt&gt;header.php&lt;/tt&gt; template file that came with your <a href="/Using_Themes" class="mw-redirect" title="Using Themes">WordPress Theme</a>, you will notice that where it says &quot;My Bl...</p> <p><b>หน้าใหม่</b></p><div>If you take a peek into the &lt;tt&gt;header.php&lt;/tt&gt; template file that came with your [[Using Themes|WordPress Theme]], you will notice that where it says &quot;My Blog Name&quot;, whatever it is, when you view your WordPress site, it doesn't say &quot;My Blog Name&quot; in the [[Stepping Into Templates|template file]]. In fact, it has a bunch of strange arrows and parentheses and words that don't make much sense.<br /> <br /> This is an example of a [[Template Tags|Template Tag]].<br /> <br /> Let's take a few steps toward learning more about what these are and how they work.<br /> <br /> ==What is a Template Tag==<br /> <br /> A template tag is code that instructs WordPress to &quot;do&quot; or &quot;get&quot; something. In the case of the &lt;tt&gt;header.php&lt;/tt&gt; template tag for your WordPress site's name, it looks like this:<br /> <br /> &lt;pre&gt;&lt;h1&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/h1&gt;&lt;/pre&gt;<br /> <br /> The template tag is &lt;tt&gt;&lt;?php bloginfo(); ?&gt;&lt;/tt&gt; wrapped in an '''H1''' heading tag. The [[Template_Tags/bloginfo|bloginfo()]] tag ''gets'' information from your [[Administration_Panels#Your_Profile|User Profile]] and [[Administration_Panels#Options_-_Configuration_Settings|Options]] &gt; [[Administration_Panels#General|General]] in the [[Administration Panels]]. In the example here, the word &lt;tt&gt;name&lt;/tt&gt; inside of the quote marks in the tag instructs the tag to &quot;get the blog's site name&quot;. This is called a '''parameter'''. <br /> <br /> ===Template Tag Parameters===<br /> <br /> In addition to the ''name'' parameter in the &lt;tt&gt;&lt;?php bloginfo(); ?&gt;&lt;/tt&gt; template tag, there is other information that can be displayed. Let's look at a few of these parameters - and you can find more information and examples on the &lt;tt&gt;[[Template_Tags/bloginfo|bloginfo()]]&lt;/tt&gt; Codex page.<br /> <br /> ; name &lt;code&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/code&gt;: As mentioned, this displays the name of the site and is set by the administrator in the [[Administration_Panels#Options_-_Configuration_Settings|Options]] &gt; [[Administration_Panels#General|General]] SubPanel by default.<br /> ; description &lt;code&gt;&lt;?php bloginfo('description'); ?&gt;&lt;/code&gt;: This is called the &quot;Tagline&quot; for your blog which is usually some kind of descriptive sentence that says &quot;My blog is about....&quot;. It is set by the administrator in the [[Administration_Panels#Options_-_Configuration_Settings|Options]] &gt; [[Administration_Panels#General|General]] SubPanel.<br /> ; url &lt;code&gt;&lt;?php bloginfo('url'); ?&gt;&lt;/code&gt;: When you want to display the URL or website address for your WordPress site, you can use URL and it will show up. This also comes from the [[Administration_Panels#Options_-_Configuration_Settings|Options]] &gt; [[Administration_Panels#General|General]] SubPanel.<br /> ; admin_email &lt;code&gt;&lt;?php bloginfo('admin_email'); ?&gt;&lt;/code&gt;: If you want to display the email of the administrator, you don't have to type it into the template files. By doing so, it may be open to [[Protection_From_Harvesters|email harvesters]] who use sophisticated software to come in and grab email addresses to use for spam. By using &lt;tt&gt;bloginfo('admin_email')&lt;/tt&gt;, the email is displayed on the page for the viewers, but the actual email address is disguised from the harvesters. Nice, huh? The administrator's email address is set in the [[Administration_Panels#Options_-_Configuration_Settings|Options]] &gt; [[Administration_Panels#General|General]] SubPanel.<br /> ; version &lt;code&gt;&lt;?php bloginfo('version'); ?&gt;&lt;/code&gt;: Sometimes you'd like to show off which version of WordPress you are using. The Themes that come with WordPress by default include this information in the footer template. It simply displays the version of WordPress your blog uses.<br /> <br /> To show the WordPress version, the template tag would look like this:<br /> <br /> &lt;pre&gt;&lt;p&gt;Powered by WordPress version &lt;?php bloginfo('version'); ?&gt;&lt;/p&gt;&lt;/pre&gt;<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:50%; margin: 10px; padding:20px&quot;&gt;Powered By WordPress version {{CurrentVersion}}&lt;/div&gt;<br /> <br /> Notice that only the version number is generated by the ''version'' parameter, not the words &quot;Powered by WordPress version&quot;. Those were written in before the tag so they would be visible on the web page.<br /> <br /> To learn more about template tag parameters, see [[Template_Tags/Anatomy_of_a_Template_Tag|Anatomy of a Template Tag]] and [[Template_Tags/How_to_Pass_Tag_Parameters|How to Pass Tag Parameters]].<br /> <br /> ==How Do You Use Template Tags?==<br /> <br /> Going through the various template tags in the [[Template Tags]] menu on the Codex, you will see that many of them are very simple, like the &lt;tt&gt;bloginfo()&lt;/tt&gt; template tag, but many look very complicated to use. Let's look at some examples of how they are used to help you understand the &quot;language&quot; of the template tag codes.<br /> <br /> As we saw in the &lt;tt&gt;bloginfo()&lt;/tt&gt; template tag, all it took was one word to change the output of the tag. This word is called a ''parameter'' and it instructs the template tag to ''do'' or ''get'' something. In this case, the instruction is to ''get name'' which displays the site's name.<br /> <br /> The template tag &lt;tt&gt;the_title()&lt;/tt&gt; displays the [[Template_Tags/the_title|title of the post]], usually at the top of your post article. This tag ''gets'' the post title and displays it, by default, but it also has a ''do'' in the parameters which will help you change the look and presentation of the post title.<br /> <br /> By default, the tag looks like this:<br /> <br /> &lt;pre&gt;&lt;?php the_title(); ?&gt;&lt;/pre&gt;<br /> <br /> And the results look something like this:<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin: 10px; padding:20px; font-size: 120%; color: navy&quot;&gt;Using WordPress Makes Me Smile&lt;/div&gt;<br /> <br /> Let's say you want to put some kind of reference that highlights the title in some way, like a graphic or [[Fun_Character_Entities|character entity]] like an arrow or bullet. Let's put a yen sign, &amp;yen; ,the sign for Japanese money, in front of our title.<br /> <br /> If you look carefully at the instructions for the tag &lt;tt&gt;the_title()&lt;/tt&gt;, you will see that the parameters are:<br /> <br /> &lt;pre&gt;&lt;?php the_title('before', 'after', display); ?&gt; &lt;/pre&gt;<br /> <br /> We want the yen sign to be ''before'' the title, with a space after the yen sign and before the title, so let's add it to the parameters:<br /> <br /> &lt;pre&gt;&lt;?php the_title('&amp;amp;yen; '); ?&gt; &lt;/pre&gt;<br /> <br /> Which, when the page is generated, would look like this:<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 120%; color: navy&quot;&gt;&amp;yen; Using WordPress Makes Me Smile&lt;/div&gt;<br /> <br /> Now, let's take this a little further and put something after the post title. Let's say you want to encourage people to read so we'll add a little incentive arrow ( &amp;raquo; ) to motivate them.<br /> <br /> &lt;pre&gt;&lt;?php the_title('&amp;amp;yen; ', ' &amp;amp;raquo;'); ?&gt; &lt;/pre&gt;<br /> <br /> Notice, we added another space before the arrow to separate it from the post title when the page is generated for viewing. <br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10x; padding:20px; font-size: 120%; color: navy&quot;&gt;&amp;yen; Using WordPress Makes Me Smile &amp;raquo;&lt;/div&gt;<br /> <br /> You can also style your title heading in many different ways. Here is another example using heading tags.<br /> <br /> &lt;pre&gt;&lt;h2&gt;&lt;?php the_title('Post Title: '); ?&gt;&lt;/h2&gt; &lt;/pre&gt;<br /> <br /> We've put the entire post title into an [[Designing_Headings|H2 heading]] and added the phrase &quot;Post Title&quot; to the beginning of the post title.<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 130%; font-weight:bold; color: navy&quot;&gt;Post Title: Using WordPress Makes Me Smile&lt;/div&gt;<br /> <br /> '''Note: Not all [[Template_Tags|template tags]] take before and after arguments, though the_title does. Check the codex page for the specific tag you're using to see what arguments it accepts.'''<br /> <br /> ===Boolean Template Tags===<br /> <br /> The above template tag example uses simple parameters separated from each other with quote marks and commas. Now consider examples of [[Template_Tags/How_to_Pass_Tag_Parameters#Boolean|Boolean Template Tags]] that connect more than one parameter together using boolean math techniques. One common boolean expression uses the &quot;and (&amp;)&quot; logic to connect the parameters. <br /> <br /> The template tag [[Template_Tags/wp_list_cats|wp_list_cats()]] is commonly found in the WordPress sidebar or menu template file. It lists the site's [[Glossary#Category|Categories]]. <br /> <br /> &lt;pre&gt;&lt;?php wp_list_cats(); ?&gt;&lt;/pre&gt;<br /> <br /> By default, some of the template tags' parameters are:<br /> <br /> * ''all'' - Displays all of the Categories<br /> * ''sort_column'' - Sorts by Category ID<br /> * ''sort_order'' - Sorts in ascending order<br /> * ''list'' - Sets the Categories in an unordered list (&lt;tt&gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;&lt;/tt&gt;)<br /> * ''optioncount'' - Does not display the count of posts within each Category<br /> * ''hide_empty'' - Based upon the first two parameters (optionall and all), does not display Categories without posts<br /> * ''use_desc_for_title'' - Uses the Category description as the link title<br /> * ''children'' - Shows the children (sub-Categories) of every Category listed<br /> <br /> An example of this category list might be:<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 110%; font-weight:bold; color: navy&quot;&gt;<br /> * Stories About My Life<br /> * Stories About My Family<br /> * Things I Want To Share<br /> ** About WordPress<br /> ** About Writing<br /> ** About Story Telling<br /> * Facts and Fiction About Life&lt;/div&gt;<br /> <br /> The indented list with &quot;About WordPress&quot;, &quot;About Writing&quot;, and &quot;About Story Telling&quot; are the '''children''' or sub-Categories of the '''parent''' Category &quot;Things I Want To Share&quot;. These titles, by default, are not the actual titles of the Categories, they are the '''descriptions''' of the Category you set in the [[Administration_Panels|Administration]] &gt; [[Administration_Panels#Categories|Manage]] &gt; [[Manage_Categories_SubPanel|Categories]] panel.<br /> <br /> If you would like to show the actual title of the Category, instead of the Category description, change the template tag to:<br /> <br /> &lt;pre&gt;&lt;?php wp_list_cats('use_desc_for_title=0'); ?&gt;&lt;/pre&gt;<br /> <br /> The zero sets the parameter to '''false''', turning off the use of the description as the title. Now the Category titles would appear:<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 110%; font-weight:bold; color: navy&quot;&gt;<br /> * My Life Stories<br /> * My Family<br /> * Sharing<br /> ** WordPress<br /> ** Writing<br /> ** Story Telling<br /> * Facts and Fiction&lt;/div&gt;<br /> <br /> Let's say that you don't want the sub-Categories for &quot;Sharing&quot; to appear on your list. You would then add the parameter to not show the children, along with the parameter for showing only titles and not descriptions, with the boolean &quot;and&quot; using the ampersand ( &lt;tt&gt;&amp;amp;&lt;/tt&gt; ).<br /> <br /> &lt;pre&gt;&lt;?php wp_list_cats('use_desc_for_title=0&amp;children=0'); ?&gt;&lt;/pre&gt;<br /> <br /> Notice there are no spaces around the ampersand. All the parameters run together without any spaces or quote marks in between, just around the whole parameter. Now the Category titles would appear as:<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 110%; font-weight:bold; color: navy&quot;&gt;<br /> * My Life Stories<br /> * My Family<br /> * Sharing<br /> * Facts and Fiction&lt;/div&gt;<br /> <br /> As another example, if you want to display the Category links as the Category title, sort the list alphabetically by name, show the number of posts within each Category, and only show the ''children'' (sub-Categories) of Category ID number 3 (&quot;Sharing&quot;), the template tag would look like this:<br /> <br /> &lt;pre&gt;&lt;?php wp_list_cats('sort_column=name&amp;sort_order=asc&amp;optioncount=1&amp;use_desc_for_title=0&amp;child_of=3'); ?&gt;&lt;/pre&gt;<br /> <br /> &lt;div style=&quot;border:1px solid blue; width:70%; margin:10px; padding:20px; font-size: 110%; font-weight:bold; color: navy&quot;&gt;<br /> ** Story Telling (21)<br /> ** WordPress (23)<br /> ** Writing (10)&lt;/div&gt;<br /> <br /> ===Template Tags and The Loop===<br /> <br /> Many of WordPress' template tags work within the [[The_Loop|WordPress Loop]]. This means that they are included in the [[Templates|template files]] as part of the php &quot;loop&quot; that generates the pages the viewer sees based upon the instructions inside of the Loop. <br /> <br /> The WordPress Loop begins with:<br /> <br /> &lt;pre&gt;&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;&lt;/pre&gt;<br /> <br /> Template tags that work within the loop must be in the middle area here, before the ending section of the Loop below:<br /> <br /> &lt;pre&gt;&lt;?php endwhile; else: ?&gt;<br /> &lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.'); ?&gt;&lt;/p&gt;<br /> &lt;?php endif; ?&gt;&lt;/pre&gt;<br /> <br /> Template tags that need to be inside of the loop include &lt;tt&gt;[[Template Tags/the_content|the_content()]]&lt;/tt&gt;, &lt;tt&gt;[[Template Tags/the_excerpt|the_excerpt()]], [[Template Tags/next_post|next_post()]], and [[Template Tags/previous_post|previous_post()]]&lt;/tt&gt;. If the template tag you want to use doesn't have to be within the Loop, like [[Template Tags/wp_list_cats|&lt;tt&gt;wp_list_cats()&lt;/tt&gt;]] and [[Template Tags/wp_list_pages|&lt;tt&gt;wp_list_pages()&lt;/tt&gt;]], then you can put it anywhere you like, for instance in the sidebar, header, or footer [[Templates|template files]].<br /> <br /> ==Learning More About Template Tags==<br /> <br /> This is just a tiny step into learning about the various powerful template tags WordPress uses to generate your website. You can learn more about the different template tags WordPress uses in the following articles and resources.<br /> <br /> * [[Template_Tags|WordPress Template Tags Catalog]]<br /> * [[Templates]]<br /> * [[Stepping Into Template Tags]]<br /> * [[Template Tags/Anatomy of a Template Tag|Anatomy of a Template Tag]]<br /> * [[Template Tags/How to Pass Tag Parameters|How to Pass Tag Parameters]]<br /> * [[The Loop|The Loop]]<br /> * [[Include Tags]]<br /> * [[Conditional Tags]]<br /> <br /> ===Styling Your Template Tags===<br /> <br /> * [[Styling Lists with CSS]]<br /> * [[Next_and_Previous_Links|Lessons: Next and Previous Links]]<br /> * [[Separating_Categories|Lessons: Separating Categories]]<br /> * [[Styling_Page-Links|Lessons: Styling Page-Links]]<br /> * [[Good_Navigation_Links|Lessons: Good Navigation Links]]<br /> * [[Formatting Date and Time]]<br /> <br /> <br /> == External Resources ==<br /> * [[fr:Decouvrir_les_Marqueurs_de_Modele]]<br /> <br /> [[Category:Getting Started]]<br /> [[Category:WordPress Lessons]]<br /> [[Category:Design and Layout]]<br /> [[Category:Template Tags]]</div> Thu, 02 Jul 2009 17:50:27 GMT Kazama http://codex.wordthai.com/%E0%B8%9E%E0%B8%B9%E0%B8%94%E0%B8%84%E0%B8%B8%E0%B8%A2:%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%A3%E0%B8%B9%E0%B9%89_tags_%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B9%83%E0%B8%99_template