
{"id":1164,"date":"2012-12-03T10:04:02","date_gmt":"2012-12-03T10:04:02","guid":{"rendered":"http:\/\/congnghepc.com\/2012\/12\/03\/to-breadcrumbs-cho-trang-wordpress-khong-cn-phi-dung-plugin\/"},"modified":"2012-12-03T10:04:02","modified_gmt":"2012-12-03T10:04:02","slug":"to-breadcrumbs-cho-trang-wordpress-khong-cn-phi-dung-plugin","status":"publish","type":"post","link":"https:\/\/tapchicntt.com\/to-breadcrumbs-cho-trang-wordpress-khong-cn-phi-dung-plugin\/","title":{"rendered":"T\u1ea1o Breadcrumbs cho trang WordPress kh\u00f4ng c\u1ea7n ph\u1ea3i d\u00f9ng Plugin"},"content":{"rendered":"<p style=\"text-align: justify;\">\n\t<strong>Breadcrumbs<\/strong> l&agrave; m\u1ed9t th&agrave;nh ph\u1ea7n kh&ocirc;ng th\u1ec3 thi\u1ebfu cho nh\u1eefng trang c&oacute; h\u1ec7 th\u1ed1ng menu \u0111\u1ed3 s\u1ed9. N&oacute; gi&uacute;p ng\u01b0\u1eddi d&ugrave;ng d\u1ec5 d&agrave;ng di chuy\u1ec3n \u0111\u1ebfn nh\u1eefng trang m&agrave; h\u1ecd mu\u1ed1n. \u0110\u1ed3ng th\u1eddi c\u0169ng l&agrave; m\u1ed9t c&ocirc;ng c\u1ee5 \u0111\u1ec3 SEO, gi&uacute;p b\u1ea1n t\u0103ng kh\u1ea3 n\u0103ng t&igrave;m ki\u1ebfm tr&ecirc;n Google. B&agrave;i vi\u1ebft n&agrave;y s\u1ebd nh\u1eb1m v&agrave;o nh\u1eefng b\u1ea1n c&oacute; \u0111am m&ecirc; l\u1eadp tr&igrave;nh, mu\u1ed1n t\u1ef1 tay t\u1ea1o cho m&igrave;nh nh\u1eefng ch\u1ee9c n\u0103ng cho web c\u1ee7a m&igrave;nh. C&ograve;n n\u1ebfu b\u1ea1n n&agrave;o mu\u1ed1n s\u1eed d\u1ee5ng plugin th&igrave; c&oacute; th\u1ec3 tham kh\u1ea3o <a href=\"http:\/\/wordpress.org\/extend\/plugins\/breadcrumb-navxt\/\" target=\"_blank\"><strong>BreadCrumb NavXT<\/strong><\/a>.<\/p>\n<p style=\"text-align: center;\">\n\t<strong><img decoding=\"async\" alt=\"\" src=\"https:\/\/dl.dropbox.com\/u\/1552467\/tutorial\/breadcrumb-navigation-for-blogger.png.jpg\" \/><\/strong><\/p>\n<p style=\"text-align: justify;\">\n\tCh&uacute;ng ta s\u1ebd ti\u1ebfn h&agrave;nh ch&egrave;n breadcrumbs v&agrave;o trang WordPress c\u1ee7a m&igrave;nh theo c&aacute;c b\u01b0\u1edbc sau \u0111&acirc;y:<\/p>\n<h2>\n\tB\u01b0\u1edbc 1 :<\/h2>\n<p style=\"text-align: justify;\">\n\tM\u1edf file <strong>functions.php<\/strong> n\u1eb1m trong folder theme c\u1ee7a b\u1ea1n. Sau \u0111&oacute; copy v&agrave; d&aacute;n \u0111o\u1ea1n code sau v&agrave;o b&ecirc;n trong n&oacute; :<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">\n\t\tfunction wp_bac_breadcrumb() {<br \/>\n\t\t\/\/Variable (symbol &gt;&gt; encoded) and can be styled separately.<br \/>\n\t\t\/\/Use &gt;&gt; for different level categories (parent &gt;&gt; child &gt;&gt; grandchild)<br \/>\n\t\t$delimiter = &#39;&lt;span&gt; &amp;raquo; &lt;\/span&gt;&#39;;<br \/>\n\t\t\/\/Use bullets for same level categories ( parent . parent )<br \/>\n\t\t$delimiter1 = &#39;&lt;span&gt; &amp;bull; &lt;\/span&gt;&#39;;<br \/>\n\t\t\/\/text link for the &#39;Home&#39; page<br \/>\n\t\t$main = &#39;Home&#39;;<br \/>\n\t\t\/\/Display only the first 30 characters of the post title.<br \/>\n\t\t$maxLength= 30;<br \/>\n\t\t\/\/variable for archived year<br \/>\n\t\t$arc_year = get_the_time(&#39;Y&#39;);<br \/>\n\t\t\/\/variable for archived month<br \/>\n\t\t$arc_month = get_the_time(&#39;F&#39;);<br \/>\n\t\t\/\/variables for archived day number + full<br \/>\n\t\t$arc_day = get_the_time(&#39;d&#39;);<br \/>\n\t\t$arc_day_full = get_the_time(&#39;l&#39;);<br \/>\n\t\t\/\/variable for the URL for the Year<br \/>\n\t\t$url_year = get_year_link($arc_year);<br \/>\n\t\t\/\/variable for the URL for the Month<br \/>\n\t\t$url_month = get_month_link($arc_year,$arc_month);<br \/>\n\t\t\/*is_front_page(): If the front of the site is displayed, whether it is posts or a Page. This is true<br \/>\n\t\twhen the main blog page is being displayed and the &#39;Settings &gt; Reading -&gt;Front page displays&#39;<br \/>\n\t\tis set to &quot;Your latest posts&quot;, or when &#39;Settings &gt; Reading -&gt;Front page displays&#39; is set to<br \/>\n\t\t&quot;A static page&quot; and the &quot;Front Page&quot; value is the current Page being displayed. In this case<br \/>\n\t\tno need to add breadcrumb navigation. is_home() is a subset of is_front_page() *\/<br \/>\n\t\t\/\/Check if NOT the front page (whether your latest posts or a static page) is displayed. Then add breadcrumb trail.<br \/>\n\t\tif (!is_front_page()) {<br \/>\n\t\t\/\/If Breadcrump exists, wrap it up in a div container for styling.<br \/>\n\t\t\/\/You need to define the breadcrumb class in CSS file.<br \/>\n\t\techo &#39;&lt;div&gt;&#39;;<br \/>\n\t\t\/\/global WordPress variable $post. Needed to display multi-page navigations.<br \/>\n\t\tglobal $post, $cat;<br \/>\n\t\t\/\/A safe way of getting values for a named option from the options database table.<br \/>\n\t\t$homeLink = get_option(&#39;home&#39;); \/\/same as: $homeLink = get_bloginfo(&#39;url&#39;);<br \/>\n\t\t\/\/If you don&#39;t like &quot;You are here:&quot;, just remove it.<br \/>\n\t\techo &#39;You are here: &lt;a href=&quot;&#39; . $homeLink . &#39;&quot;&gt;&#39; . $main . &#39;&lt;\/a&gt;&#39; . $delimiter;<br \/>\n\t\t\/\/Display breadcrumb for single post<br \/>\n\t\tif (is_single()) { \/\/check if any single post is being displayed.<br \/>\n\t\t\/\/Returns an array of objects, one object for each category assigned to the post.<br \/>\n\t\t\/\/This code does not work well (wrong delimiters) if a single post is listed<br \/>\n\t\t\/\/at the same time in a top category AND in a sub-category. But this is highly unlikely.<br \/>\n\t\t$category = get_the_category();<br \/>\n\t\t$num_cat = count($category); \/\/counts the number of categories the post is listed in.<br \/>\n\t\t\/\/If you have a single post assigned to one category.<br \/>\n\t\t\/\/If you don&#39;t set a post to a category, WordPress will assign it a default category.<br \/>\n\t\tif ($num_cat &lt;=1)&nbsp; \/\/I put less or equal than 1 just in case the variable is not set (a catch all).<br \/>\n\t\t{<br \/>\n\t\techo get_category_parents($category[0],&nbsp; true,&#39; &#39; . $delimiter . &#39; &#39;);<br \/>\n\t\t\/\/Display the full post title.<br \/>\n\t\techo &#39; &#39; . get_the_title();<br \/>\n\t\t}<br \/>\n\t\t\/\/then the post is listed in more than 1 category.<br \/>\n\t\telse {<br \/>\n\t\t\/\/Put bullets between categories, since they are at the same level in the hierarchy.<br \/>\n\t\techo the_category( $delimiter1, multiple);<br \/>\n\t\t\/\/Display partial post title, in order to save space.<br \/>\n\t\tif (strlen(get_the_title()) &gt;= $maxLength) { \/\/If the title is long, then don&#39;t display it all.<br \/>\n\t\techo &#39; &#39; . $delimiter . trim(substr(get_the_title(), 0, $maxLength)) . &#39; &#8230;&#39;;<br \/>\n\t\t}<br \/>\n\t\telse { \/\/the title is short, display all post title.<br \/>\n\t\techo &#39; &#39; . $delimiter . get_the_title();<br \/>\n\t\t}<br \/>\n\t\t}<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for category and sub-category archive<br \/>\n\t\telseif (is_category()) { \/\/Check if Category archive page is being displayed.<br \/>\n\t\t\/\/returns the category title for the current page.<br \/>\n\t\t\/\/If it is a subcategory, it will display the full path to the subcategory.<br \/>\n\t\t\/\/Returns the parent categories of the current category with links separated by &#39;&raquo;&#39;<br \/>\n\t\techo &#39;Archive Category: &quot;&#39; . get_category_parents($cat, true,&#39; &#39; . $delimiter . &#39; &#39;) . &#39;&quot;&#39; ;<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for tag archive<br \/>\n\t\telseif ( is_tag() ) { \/\/Check if a Tag archive page is being displayed.<br \/>\n\t\t\/\/returns the current tag title for the current page.<br \/>\n\t\techo &#39;Posts Tagged: &quot;&#39; . single_tag_title(&quot;&quot;, false) . &#39;&quot;&#39;;<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for calendar (day, month, year) archive<br \/>\n\t\telseif ( is_day()) { \/\/Check if the page is a date (day) based archive page.<br \/>\n\t\techo &#39;&lt;a href=&quot;&#39; . $url_year . &#39;&quot;&gt;&#39; . $arc_year . &#39;&lt;\/a&gt; &#39; . $delimiter . &#39; &#39;;<br \/>\n\t\techo &#39;&lt;a href=&quot;&#39; . $url_month . &#39;&quot;&gt;&#39; . $arc_month . &#39;&lt;\/a&gt; &#39; . $delimiter . $arc_day . &#39; (&#39; . $arc_day_full . &#39;)&#39;;<br \/>\n\t\t}<br \/>\n\t\telseif ( is_month() ) {&nbsp; \/\/Check if the page is a date (month) based archive page.<br \/>\n\t\techo &#39;&lt;a href=&quot;&#39; . $url_year . &#39;&quot;&gt;&#39; . $arc_year . &#39;&lt;\/a&gt; &#39; . $delimiter . $arc_month;<br \/>\n\t\t}<br \/>\n\t\telseif ( is_year() ) {&nbsp; \/\/Check if the page is a date (year) based archive page.<br \/>\n\t\techo $arc_year;<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for search result page<br \/>\n\t\telseif ( is_search() ) {&nbsp; \/\/Check if search result page archive is being displayed.<br \/>\n\t\techo &#39;Search Results for: &quot;&#39; . get_search_query() . &#39;&quot;&#39;;<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for top-level pages (top-level menu)<br \/>\n\t\telseif ( is_page() &amp;&amp; !$post-&gt;post_parent ) { \/\/Check if this is a top Level page being displayed.<br \/>\n\t\techo get_the_title();<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb trail for multi-level subpages (multi-level submenus)<br \/>\n\t\telseif ( is_page() &amp;&amp; $post-&gt;post_parent ) {&nbsp; \/\/Check if this is a subpage (submenu) being displayed.<br \/>\n\t\t\/\/get the ancestor of the current page\/post_id, with the numeric ID<br \/>\n\t\t\/\/of the current post as the argument.<br \/>\n\t\t\/\/get_post_ancestors() returns an indexed array containing the list of all the parent categories.<br \/>\n\t\t$post_array = get_post_ancestors($post);<br \/>\n\t\t\/\/Sorts in descending order by key, since the array is from top category to bottom.<br \/>\n\t\tkrsort($post_array);<br \/>\n\t\t\/\/Loop through every post id which we pass as an argument to the get_post() function.<br \/>\n\t\t\/\/$post_ids contains a lot of info about the post, but we only need the title.<br \/>\n\t\tforeach($post_array as $key=&gt;$postid){<br \/>\n\t\t\/\/returns the object $post_ids<br \/>\n\t\t$post_ids = get_post($postid);<br \/>\n\t\t\/\/returns the name of the currently created objects<br \/>\n\t\t$title = $post_ids-&gt;post_title;<br \/>\n\t\t\/\/Create the permalink of $post_ids<br \/>\n\t\techo &#39;&lt;a href=&quot;&#39; . get_permalink($post_ids) . &#39;&quot;&gt;&#39; . $title . &#39;&lt;\/a&gt;&#39; . $delimiter;<br \/>\n\t\t}<br \/>\n\t\tthe_title(); \/\/returns the title of the current page.<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for author archive<br \/>\n\t\telseif ( is_author() ) {\/\/Check if an Author archive page is being displayed.<br \/>\n\t\tglobal $author;<br \/>\n\t\t\/\/returns the user&#39;s data, where it can be retrieved using member variables.<br \/>\n\t\t$user_info = get_userdata($author);<br \/>\n\t\techo&nbsp; &#39;Archived Article(s) by Author: &#39; . $user_info-&gt;display_name ;<br \/>\n\t\t}<br \/>\n\t\t\/\/Display breadcrumb for 404 Error<br \/>\n\t\telseif ( is_404() ) {\/\/checks if 404 error is being displayed<br \/>\n\t\techo&nbsp; &#39;Error 404 &#8211; Not Found.&#39;;<br \/>\n\t\t}<br \/>\n\t\telse {<br \/>\n\t\t\/\/All other cases that I missed. No Breadcrumb trail.<br \/>\n\t\t}<br \/>\n\t\techo &#39;&lt;\/div&gt;&#39;;<br \/>\n\t\t}<br \/>\n\t\t}<\/p>\n<\/blockquote>\n<h2>\n\tB\u01b0\u1edbc 2 :<\/h2>\n<p style=\"text-align: justify;\">\n\tC&aacute;c b\u1ea1n t&igrave;m \u0111\u1ebfn file <strong>header.php<\/strong> c\u0169ng n\u1eb1m c&ugrave;ng v\u1ecb tr&iacute; v\u1edbi file <strong>funcitons.php<\/strong> v&agrave; d&aacute;n \u0111o\u1ea1n code sau v&agrave;o b&ecirc;n trong n&oacute; :<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">\n\t\t&lt;?php<br \/>\n\t\t&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; if (function_exists(&#39;wp_bac_breadcrumb&#39;)) {wp_bac_breadcrumb();}<br \/>\n\t\t?&gt;<\/p>\n<\/blockquote>\n<h2>\n\tB\u01b0\u1edbc 3<\/h2>\n<p style=\"text-align: justify;\">\n\tT\u1ea1o css cho breadcrumbs.<\/p>\n<p style=\"text-align: justify;\">\n\tVi\u1ec7c t\u1ea1o breadcrumbs coi nh\u01b0 \u0111&atilde; xong, b&acirc;y gi\u1edd ch&uacute;ng ta ch\u1ec9 c\u1ea7n ch&egrave;n th&ecirc;m v&agrave;i hi\u1ec7u \u1ee9ng css cho n&oacute; ch\u1ea1y m\u01b0\u1ee3t l&agrave; \u0111\u01b0\u1ee3c. C&aacute;c b\u1ea1n c&oacute; th\u1ec3 copy \u0111o\u1ea1n code sau v&agrave;o style.css trong folder theme c\u1ee7a b\u1ea1n.<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">\n\t\t\/* Styling Breacrumb Navigation by BOUTROS ABICHEDID *\/<br \/>\n\t\t.breadcrumb{<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; width:645px;<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; float:left;<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; padding:0 0 0 47px;<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; margin:9px 0 0 0;<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; font-size:90%;<br \/>\n\t\t&nbsp;&nbsp;&nbsp;&nbsp; clear:both;<br \/>\n\t\t}<br \/>\n\t\t.delimiter{<br \/>\n\t\t&nbsp;&nbsp;&nbsp; color:#000;<br \/>\n\t\t&nbsp;&nbsp;&nbsp; background-color:inherit;<br \/>\n\t\t}<br \/>\n\t\t.delimiter1{<br \/>\n\t\t&nbsp;&nbsp;&nbsp; color: #627FC3;<br \/>\n\t\t&nbsp;&nbsp;&nbsp; background-color:inherit;<br \/>\n\t\t}<\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">\n\t<strong>Ch&uacute;c c&aacute;c b\u1ea1n th&agrave;nh c&ocirc;ng !<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\n\t<strong><img decoding=\"async\" alt=\"\" src=\"https:\/\/dl.dropbox.com\/u\/1552467\/tutorial\/breadcrumb-navigation-for-blogger.png.jpg\" style=\"width: 100px; height: 88px; margin-left: 5px; margin-right: 5px; float: left;\" \/>Breadcrumbs<\/strong> l&agrave; m\u1ed9t th&agrave;nh ph\u1ea7n kh&ocirc;ng th\u1ec3 thi\u1ebfu cho nh\u1eefng trang c&oacute; h\u1ec7 th\u1ed1ng menu \u0111\u1ed3 s\u1ed9. N&oacute; gi&uacute;p ng\u01b0\u1eddi d&ugrave;ng d\u1ec5 d&agrave;ng di chuy\u1ec3n \u0111\u1ebfn nh\u1eefng trang m&agrave; h\u1ecd mu\u1ed1n. \u0110\u1ed3ng th\u1eddi c\u0169ng l&agrave; m\u1ed9t c&ocirc;ng c\u1ee5 \u0111\u1ec3 SEO, gi&uacute;p b\u1ea1n t\u0103ng kh\u1ea3 n\u0103ng t&igrave;m ki\u1ebfm tr&ecirc;n Google. B&agrave;i vi\u1ebft n&agrave;y s\u1ebd nh\u1eb1m v&agrave;o nh\u1eefng b\u1ea1n c&oacute; \u0111am m&ecirc; l\u1eadp tr&igrave;nh, mu\u1ed1n t\u1ef1 tay t\u1ea1o cho m&igrave;nh nh\u1eefng ch\u1ee9c n\u0103ng cho web c\u1ee7a m&igrave;nh. C&ograve;n n\u1ebfu b\u1ea1n n&agrave;o mu\u1ed1n s\u1eed d\u1ee5ng plugin th&igrave; c&oacute; th\u1ec3 tham kh\u1ea3o <a href=\"http:\/\/wordpress.org\/extend\/plugins\/breadcrumb-navxt\/\" target=\"_blank\"><strong>BreadCrumb NavXT<\/strong><\/a>.<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[143],"tags":[],"class_list":["post-1164","post","type-post","status-publish","format-standard","hentry","category-thu-thuat-wordpress"],"views":470,"_links":{"self":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/1164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/comments?post=1164"}],"version-history":[{"count":0,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/posts\/1164\/revisions"}],"wp:attachment":[{"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/media?parent=1164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/categories?post=1164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tapchicntt.com\/rest-api\/wp\/v2\/tags?post=1164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}