And you, be ye fruitful, and multiply; bring forth abundantly in the earth, and multiply therein.

Genesis 9:7

WordPress is a very popular content management system. Written in the PHP language and using a relational database. There are also many plugins (modules) for this platform that make it a multi-functional solution for any need.

By default, a user can create three types of WordPress publications.

  1. Posts are entries that appear in reverse order by date on your homepage and/or blog page. Posts usually have comment boxes below them and are included in your site’s RSS feed.
  2. Media is a type of content that is uploaded by the user to the Media Library /wp-content/uploads/ directory and is in the form of a multimedia file (image, video, and other types). Such a file can be standalone or inserted into a post or page.
  3. Pages are static and are not affected by date. Think of them as more permanent fixtures of your site — an About page, a Contact page, and a Home page are great examples of this.

Built-in WordPress functions

is_single( int|string|int[]|string[] $post = '' )

Determines whether the query is for an existing single post.

 

get_media_item( int $attachment_id, string|array $args = null )

Retrieves HTML form for modifying the image attachment.

 

is_page( int|string|int[]|string[] $page = '' )

Determines whether the query is for an existing single page.

 

is_feed( string|string[] $feeds = '' )

Determines whether the query is for a feed.

 

Simple solution to determine the type of content and the categories

<?php


// Check if this is a post.
if (is_single()) {
    echo 'This is a post <br>';
}
// Check if this is a page.
if (is_page()) {
    echo 'This is a page <br>';
}
// Check if this is a feed.
if (is_feed()) {
    echo 'This is a feed <br>';
}
// Check for categories.
$categories = get_the_category();
if (!empty($categories)) {
    foreach($categories as $category) {
        echo $category->name . "<br>";
        echo category_description($category);
    }
}

?>
Last modified: July 5, 2022

Author

Comments

Write a Reply or Comment

Your email address will not be published.