Skip to content

Instantly share code, notes, and snippets.

@Sstobo
Sstobo / gist:21c7569734658260370ae8de2fbae06f
Last active November 8, 2017 19:50
[wordpress loop] #wp #setup #php
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<h2>Nothing found!</h2>
<?php endif; ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
</head>
<body>
<h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
<p class="description"><?php bloginfo( 'description' ); ?></p>
@Sstobo
Sstobo / gist:9f434bb28252070ec5c1a9812987a508
Created November 9, 2017 17:40
[wordpress get_x] #setup #wp
<?php get_header(); ?>
<div>
<?php
// The loop might go here...
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
@Sstobo
Sstobo / gist:9a7577ad12fe5fe40346752fe6a22510
Created November 9, 2017 17:53
[custom template page FOR ABOUT PAGE] #wp #setup
<?php
/**
* Template Name: Full-width
*/
get_header(); ?>
<div id="primary" class="content-area">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // End of the loop. ?>
</div><!-- #primary -->
@Sstobo
Sstobo / gist:3d1f52e0a025210ef34015ab7a51cbea
Created November 9, 2017 19:11
[WP comments template] #wp #comments #template
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
@Sstobo
Sstobo / gist:bd6b751a6e6f3ad951b52ef973d633c2
Created November 9, 2017 19:21
[WP sidebar] #wp #sidebar
To create a widgetized area in a WordPress theme, in your functions.php file you will need to add:
function my_widgets_init() {
register_sidebar( array(
'name' => esc_html( 'Sidebar' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
Like our sidebars, we must "register" all of the navigation menus we want to add to our WordPress theme:
In your functions.php file:
function my_theme_setup() {
register_nav_menus( array(
'primary' => 'Primary Menu',
) );
}
add_action( 'after_setup_theme', 'my_theme_setup' );
@Sstobo
Sstobo / gist:8271af7d77e5e2dc742316d50c863568
Created November 9, 2017 19:31
[WP closing tags] #wp
Don't Forget!
When you build a WP theme, you want to make sure you include the following right before your closing <head> tag:
<!-- ...all of the <head> stuff above -->
<?php wp_head(); ?>
</head>
And this right before the closing body tag:
<!-- ...all of the <body> stuff above -->
@Sstobo
Sstobo / gist:0abc488d9cdb9ecada0cb86289f2142f
Created November 10, 2017 00:51
[interviewing, job culture, resume]
https://redacademy-dev-van.slack.com/files/U75NWHJDR/F7Z2MG24X/ppd_notes.txt
@Sstobo
Sstobo / gist:b898671626ef36b754ad7fcd69bf7b08
Created November 10, 2017 17:52
[WP actions filters] #wp
Actions vs. Filters
Actions Filters*
Used when something has to be added/done Used when something has to be changed
Declared with do_action() Declared with apply_filters()
Used with add_action() Used with add_filter()