WordPress determines how different pages display different content

Source: Internet
Author: User
Tags php code

Through the application of the WordPress judgment function, we can achieve different content to display different page effect. For example, if you want to show links only on the homepage, you can apply the following code:

<?php if (Is_home ()) {?>

Here for the Friendship link code

<?php}?>

If you want the sidebar's Google ads to be not displayed on the article page, display other content when the ad isn't displayed.

<?php if (Is_single ()):?>

Other Advertising Code

<?php Else:?>

Google Advertising Code

<?php endif;?>

In this way, the article page will display "other ads" rather than "Google Ads".

Special attention is: If your sidebar is implemented with gadgets, to the small tool or article page to support PHP code, you need to install a plugin: exec-php.

The following is a common WordPress judgment function, the need for friends can collect spare

1. The article displays the Judgment function

Is_single () to determine whether the page is a specific article

Is_single (' 2 ') determines whether the page is a specific article (id=2)

Is_single (' Beef Stew ') the page that determines whether a specific article (title is judged)

Is_single (' Beef-stew ') determines whether the page is a specific article (slug judgment)

Comments_open () Whether the message is open

Pings_open () whether to open ping

2. Page Display judgment function

Is_page () is a page

Is_page (' a ') ID to determine if it is a page with an ID of 42

Is_page (' about Me ') judge the title

Is_page (' about-me ') slug judgment

3. Classification Display judgment function

Whether the Is_category () is classified

Is_category (' 6 ') ID to determine whether the category is ID 6

Is_category (' cheeses ') classification title judgment

Is_category (' cheeses ') classification slug judgment

In_category (' 5 ') determines whether the current article belongs to Category 5

4. Authors Archive display judgment function

Is_author () displays all the author's pages

Is_author (' 1337 ') shows author number 1337 page

Is_author (' Elite Hacker ') displays the current author's page by nickname

Is_author (' Elite-hacker ')

5. The following is through different judgments to achieve the year, month, day, time and other means to display the archive

Time File display judgment function

Is_date ()

Is_year ()

Is_month ()

Is_day ()

Is_time ()

Determine if the current archive page is_archive ()

Determine if the search is Is_search ()

Determine if the page is 404 is_404 ()

Decide whether to flip the page is_paged ()

For example, your current blog is http://www.php2.cc/display http://www.php2.cc/?paged=2, this judgment will return true, through this function can cooperate with is_home to control some of the interface can only be displayed on the first page, for example:

if (Is_home () &&!is_paged ())

6. Other Display judgment function

Is_attachment ()

Is_feed ()

Is_trackback ()

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.