Unit IV Wordpress - Notes
Unit IV Wordpress - Notes
A WordPress theme changes the design of your website, often including its layout.
Changing your theme changes how your site looks on the front-end, i.e. what a
visitor sees when they browse to your site on the web. Themes take the content
and data stored by WordPress and display it in the browser. When you create a
WordPress theme, you decide how that content looks and is displayed.
At their most basic level, WordPress themes are collections of different files that work
together to create what you see, as well as how your site behaves.
Required files
Classic themes are built with PHP files – including template files
Block themes are built with blocks and HTML files
Localization files
CSS files
Graphics
JavaScript
Text files – usually license info, readme.txt instructions, and a changelog file.
To access the Customizer for your theme, you can open your WP Admin and go to
Appearance → Customize.
If you don’t see a Customize option under the Appearance menu, you might be using a block
theme. Block themes don’t use the Customizer. Instead, you’ll use the Site Editor, which is
what we covered above.
As you’re editing your design, you can preview your changes on different
devices, using the three icons in the sidebar’s bottom-right corner:
How to Make Your Theme Customizations Live
When you’re happy with your changes, click on the Save
Changes or Publish button at the top of the sidebar. WordPress will now
apply these edits to your live website.
If you’re not quite ready to publish your changes but you don’t want to lose
your work, you can also click the gear icon next to the button and
select Save Draft.
This will save your changes inside the Customizer, but without making
them live on your website. That is, your visitors won’t see the changes yet if
you save them as a draft, but you can still come back to the Customizer and
pick up where you left off.
That means you can customize your site’s design by dragging and dropping
layout and content elements on a visual preview of your site.
Each page builder has its own unique customization procedure, so see their
documentation if you choose this path.
When you use a page builder plugin to customize your site, you need to be
willing to commit to using the page builder plugin over the long term.
All of the changes and customizations that you make will only work for as
long as you use that page builder plugin.
If you decide you want to stop using the page builder in the future (or
switch to a different page builder), you will lose pretty much all of your
design customizations, and you’ll need to manually recreate everything.
Now, that doesn’t mean you should never use a page builder plugin to
customize your site. But you should consider the lock-in effect and your
commitment to using that page builder over the long term before you make
any final decision.
If you’re not sure that you’re willing to use the page builder plugin over the
long term, it’s probably a better option to stick with core WordPress
features such as the Site Editor (for block-enabled themes) or the
Customizer (for classic WordPress themes).
CUSTOMIZATION OF THEME WITH CSS:
If your site is accessible through wp-admin, you can edit the files using the
default WordPress menu options.
The Loop is the default mechanism WordPress uses for outputting posts
through a theme’s template files. How many posts are retrieved is
determined by the number of posts to show per page defined in the
Reading settings. Within the Loop, WordPress retrieves each post to be
displayed on the current page and formats it according to your theme’s
instructions.
The Loop extracts the data for each post from the WordPress database
and inserts the appropriate information in place of each template tag. Any
HTML or PHP code in The Loop will be processed for each post.
To put it simply, the Loop is true to its name: it loops through each post
retrieved for the current page one at a time and performs the action
specified in your theme.
You can use the Loop for a number of different things, for example to:
Copy
<?php
if ( have_posts() ) :
endwhile;
endif;
?>
This loop says that when there are posts, loop through and display the
posts. Broken down into more detail:
The Loop should be placed in index.php, and in any other templates which
are used to display post information. Because you do not want to duplicate
your header over and over, the loop should always be placed after the call
to get_header(). For example:
<?php
get_header();
if ( have_posts() ) :
endwhile;
endif;
?>
In the above example, the end of the Loop is shown with an endwhile and
endif. The Loop must always begin with the same if and while statements,
as mentioned above and must end with the same end statements.
Creation of custom post types (CPTs) and custom taxonomies in WordPress can be
done inside a theme’s functions.php file or inside a plugin. Keep in mind that the
custom post type and custom taxonomy will disappear if you switch theme or
deactivate the plugin. So it’s safe to temporarily remove the CPT registration from
the theme, and move it into a plugin – as long as you keep the same custom post
type or taxonomy identifier slug/ID.
For creating (and modifying) a CPT or taxonomy, always use the init hook. Placing it
in root of functions.php (outside a hook) or any other hook will cause problems.
For creating a custom post type you use the register_post_type function. It accepts
two parameters; first the post type identifier and second an array with all arguments.
The post type identifier is a slug version name of your post type. For example
WordPress’ built-in post types posts and pages are identified as ‘ post‘ and ‘page‘. The
identifier must be unique, it must follow a set of rules (lowercase, no spaces etc) and
not be one of WordPress’ reserved slugs.
This is what I have learned to be the minimum but perfectly good enough arguments for
registering a post type; considering that it’s a normal public CPT, and you wish to override
any labels that says “post” or “page” with the actual name of your CPT
A custom taxonomy can be attached to one of WordPress’ post types (posts, pages),
or to a custom post type. You can also attach multiple taxonomies to a post type.
When you register a taxonomy, you need to provide the post type(s) you want it to
be attached to.
A taxonomy can either be hierarchical (like post categories where you can make a
tree-based structure) or tag-based (like post tags). This is really the only
consideration you need to know beforehand, with the exception of its identifier slug.
As with CPTs, the identifying slug to a taxonomy needs to be unique and follow a set
of rules.
You get it. Having multiple blogs on multiple sites just isn’t what you
want. Even though that’s technically the WordPress way of doing
things. When you look at Settings – Reading, you can only choose 1
page to be the home for your Posts, which will display them all as a
feed.
However, there’s hope. We are going to offer two solutions for how
you can have multiple WordPress blogs on one WordPress install.
Both of these ways are built into WordPress itself. They’re pretty
simple to set up and use (for the most part). We are not using plugins
to do this. However, even though they are built i, these methods aren’t
just clicking a button that says Create New Blog. (After installing
Multisite, will be, though!) With that in mind, let’s push forward and
see what we can do to run multiple blogs rather than what we can’t.
The first thing to do is log into your site and navigate to Posts –
Categories. It will be near the top of the left sidebar in the admin
panel.
You will see four fields for your Categories on this screen. Each of
them is important to properly set up your WordPress site to host
multiple blogs.
1. Name – This one will be the displayed title of the blog. If you
have Categories indexed by search engines, the archive will bear
this title. If not, this name will be for internal use only, though it
might display in some themes.
2. Slug – Like a Post slug, the Slug for a Category indicates where
you can find the category archive. Depending on your permalink
settings (under Settings – Permalinks), this could also be part
of your post structure.
3. Parent Category – The parent category is very important for
running multiple blogs on one site. You might run a brand
called The Umbrella Corporation that will have its own posts, and
your blogs might be called Raccoon City, Leon’s Journal,
and Claire’s Diary. Each of those would be separate but tied to
the main brand. You can also do this for a parent category as a
primary blog for a podcast, but use subcategories as season
archives. This one is optional, depending on the structure you
want.
4. Description – The description might not show up everywhere
(or anywhere) depending on your theme. But it can be indexed
by search engines, and it is good for the internal organization if
nothing else. Definitely worth putting a Tweet’s worth of info
here.
Once completed, the new Categories will appear to the right of the
page as a list. Each Parent Category will be listed above its respective
children.
Additionally, whether you actually check the box or not, the Child is
always going to be listed under the Category in archives and URL
structures. So you might want to not use the Parent/Child hierarchy
and set them all as top-level categories if they’re all autonomous.
Integration of third party api:
It can do both for you if you need to execute GET or POST data. And, if you
are a newbie to WordPress, it’s the perfect solution for completing API
integration within minimal time. However, before you utilize the WPGetAPI
plugin, you must understand the basics of API and its working.
After the plugin activation, choose the API you want to integrate, similar to the
Quotable API we use in this procedure. Before you start the integration,
undergo the API documentation to learn about its authentication mechanism,
proper functionality, API base URL, and more. Understanding API is essential,
as all such data will be used in further procedures.
Moreover, WPGetAPI comes in two categories, the free and the pro version. If
you are starting, then the free version is appropriate. Otherwise, you must opt
for the pro version for extended features.
You need to select the Setup tab to fill out the details of the third-party API.
Further, you must enter the details in three mandatory fields – API Name,
Unique ID, and Base URL.
The API Name can be anything you choose, as its primary purpose is to
identify the API. In this case, we have set it up as Quotable, as it becomes
easy to refer to Quotable API. Further, Unique ID is also similar to API Name,
as you can input anything. But remember to create an id with only lowercase
letters, underscore, and numerical values.
For the Base URL field, you need to undergo the API’s documentation, as it’s
present in it. The Quotable API base URL is ‘https://api.quotable.io.’
After filling in all the necessary details, Save them and move further with the
process through the WPGetAPI interface.
You can easily find the endpoint needed for its successful integration in your
API’s documentation. After saving the API Name, Unique ID, and Base URL,
you must configure the endpoint. The WPGetAPI plugin will show you a form
asking for API’s endpoint details.
Further, you should input the following details:
Unique ID
Likewise, for the API unique ID, you need to create such an id for the endpoint
reference. It would be used while configuring the data display on the
webpage.
Endpoint
It’s the endpoint of the API, which you can get from the documentation or
other legit sources of the API.
Method
GET, POST, PUT, PATCH, and DELETE are the primary API methods you
can enter in the method field. In the Quotable API case, we will use the GET
method, as we need to get a random quote to display on our site.
Result Format
You should declare the format in which you want to receive data from the API.
You can select from the primary two alternatives – 1) JSON String and 2) PHP
Array. Experts prefer JSON string due to its compatibility with template tags
and shortcode data display methods.
After inputting all the endpoint details, the plugin will unblock the Test
Endpoint button. And when you click on it, the API testing will get initiated. In
our case, we have declared the GET method, which means the API will fetch
a random quote.