Skip to content

Instantly share code, notes, and snippets.

@harshclimate
harshclimate / wp-query-ref.php
Created January 12, 2018 00:24 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@harshclimate
harshclimate / archive.php
Created January 12, 2018 04:13 — forked from vividvilla/archive.php
Archive functions
// Display weekly archives
<?php wp_get_archives('type=weekly'); ?>
// Last 10 weeks archive
<?php wp_get_archives('type=weekly&limit=10'); ?>
// Monthly archive with post count
@harshclimate
harshclimate / archive.php
Last active January 13, 2018 04:37
This is a WP_Query + original loop with post thumbnail archive.
<?php get_header(); ?>
<article>
<div class="left">
<h3>Categories used on the website</h3>
<div class="cat-listing">
<span class="category-name">Category name</span><span class="times-used">Times used</span>
<p>
<?php
$args = array(
@harshclimate
harshclimate / functions.php
Last active January 14, 2018 23:07
Append the date to main navigation menu via functions.php
<?php
// I need to make sure that scripts and styles are able to be recognized on the website.
function HC_Scripts() {
wp_enqueue_style('style' , get_stylesheet_uri());
wp_enqueue_style('grid' , get_template_directory_uri() .'/grid.css', array(), null, 'all');
wp_enqueue_style('fonts' , 'https://fonts.googleapis.com/css?family=PT+Sans:400,400i|Roboto+Condensed:400,700', false );
wp_enqueue_style('load-fa', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css' );
}
add_action( 'wp_enqueue_scripts', 'HC_Scripts' );
?><?php
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@harshclimate
harshclimate / Mark parent navigation active when on custom post type single page Mark (highlight) custom post type parent as active item in Wordpress Navigation. When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 );
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Getting the post type of the current post
<?php get_header(); ?>
<?php
$args1 = array(
'post_type' => 'post',
'orderby' => 'rand',
'category_name' => 'wineries',
'posts_per_page' => 1
); $wineries = new WP_Query($args1);
?>