Wp text gadgets run php code to implement breadcrumb navigation steps

Source: Internet
Author: User
Wp text gadgets run php code to implement breadcrumb navigation steps in wordpress, many themes provide many gadgets, one of which is useful is text gadgets.

Next, let's take a look at how to make the text gadgets run php code to implement the breadcrumb navigation.

1. First, add the crumb navigation function in function. php under the topic.

// Add the breadcrumbs navigation function iaccepted_breadcrumbs () {$ delimiter = '»'; $ name = 'home'; // text for the 'home' link $ currentBefore = ''; $ currentAfter = ''; if (! Is_home ()&&! Is_front_page () | is_paged () {echo'

'; Global $ post; $ home = get_bloginfo ('URL'); echo ''. $ name. ''. $ delimiter. ''; if (is_category () {global $ wp_query; $ cat_obj = $ wp_query-> get_queried_object (); $ thisCat = $ cat_obj-> term_id; $ thisCat = get_category ($ thisCat); $ parentCat = get_category ($ thisCat-> parent); if ($ thisCat-> parent! = 0) echo (get_category_parents ($ parentCat, TRUE ,''. $ delimiter. ''); echo $ currentBefore; single_cat_title (); echo $ currentAfter;} elseif (is_day () {echo ''. get_the_time ('Y '). ''. $ delimiter. ''; echo ''. get_the_time ('F '). ''. $ delimiter. ''; echo $ currentBefore. get_the_time ('D '). $ currentAfter;} elseif (is_month () {echo ''. get_the_time ('Y '). ''. $ delimiter.' '; Echo $ currentBefore. get_the_time ('F '). $ currentAfter;} elseif (is_year () {echo $ currentBefore. get_the_time ('Y '). $ currentAfter;} elseif (is_single () {$ cat = get_the_category (); $ cat = $ cat [0]; echo get_category_parents ($ cat, TRUE ,''. $ delimiter. ''); echo $ currentBefore; the_title (); echo $ currentAfter;} elseif (is_page ()&&! $ Post-> post_parent) {echo $ currentBefore; the_title (); echo $ currentAfter;} elseif (is_page () & $ post-> post_parent) {$ parent_id = $ post-> post_parent; $ breadcrumbs = array (); while ($ parent_id) {$ page = get_page ($ parent_id ); $ breadcrumbs [] = 'id ). '"> '. get_the_title ($ page-> ID ). ''; $ parent_id = $ page-> post_parent;} $ breadcrumbs = array_reverse ($ breadcrumbs); foreach ($ breadcrumbs as $ crumb) echo $ crumb. ''. $ delimiter. ''; echo $ currentBefore; the_title (); echo $ currentAfter;} elseif (is_search () {echo $ currentBefore. get_search_query (). $ currentAfter;} elseif (is_tag () {echo $ currentBefore; single_tag_title (); echo $ currentAfter;} elseif (is_author () {global $ author; $ userdata = get_userdata ($ author); echo $ currentBefore. ''. $ userdata-> display_name. $ currentAfter;} elseif (is_404 () {echo $ currentBefore. 'error 404 '. $ currentAfter;} if (get_query_var ('paged') {if (is_category () | is_day () | is_month () | is_year () | is_search () | is_tag () | is_author () echo '('; echo _ ('page '). ''. get_query_var ('paged'); if (is_category () | is_day () | is_month () | is_year () | is_search () | is_tag () | is_author () echo ')';} echo'

';}}

2. to make the gadgets run php code, you must add the following code to functions. php under the topic:

// Let the php code function php_text ($ text) {if (strpos ($ text, '<'.'? ')! = False) {ob_start (); eval ('? '. '> '. $ Text); $ text = ob_get_contents (); ob_end_clean ();} return $ text;} add_filter ('widget _ text', 'php _ text', 90 );

This ensures that php code can be embedded in the text tool and executed properly.

3. select the location where you want to add a text widget and enter the title as follows:

Your current location:
 

In this way, you can run the php code in the text tool to implement the breadcrumb navigation. For more information, see the navigation at the top of this article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.