Created
March 6, 2019 23:49
-
-
Save savyounts/4ad80447b790d9c69dc4ac2e9b5aa192 to your computer and use it in GitHub Desktop.
The beginnings of PHP and Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In WordPress, you can have different types of "posts", these posts can be categories of different types of information to be displayed on your site. | |
In your project's theme folder there should be all sorts of files for different pages. Some of these files start with "single". Single.php is what determines how single blog posts look on your site. For other | |
post categories, make a new file called single-name_of_categorey.php (ex: single-locations.php). WordPress automatically knows that this file should handle Location posts (assuming you have a category called | |
Locations.) | |
In this singles page, you can use WordPress functions like get_header(), get_fields(), get_previous_post(), get_the_title(), get_permalink() or get_post_meta() (along with many other options) to grab the information | |
you need from your single post. Do all of this within PHP tags and you can set up variables and any logic you may need later in your HTML. | |
After closing your PHP tag, you can start writing your HTML markup. To use the PHP variables you created before you can insert PHP tags where you need them. | |
ex: | |
<div> <?php echo get_title(); ?> </div> | |
or | |
<div> <?php echo $myVariable ?> </div> | |
Before or after your HTML code you can use WordPress function to grab code from other templates you have already built like header, footer or sidebar. | |
get_header() grabs the information from the theme header or if you have multiple header types you can specify which one by giving it an argument | |
https://developer.wordpress.org/reference/functions/get_header/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment