Skip to content

Instantly share code, notes, and snippets.

@matheuscl
matheuscl / wp-load-more-posts-ajax.php
Created April 1, 2016 12:45
[WP] Load more posts using AJAX without plugins xD
class My_Custom_Theme_Options {
function odin_theme_settings_example() {
$settings = new Odin_Theme_Options ( 'odin-settings', // Slug/ID of the Settings Page (Required)
'Theme Settings', // Settings page name (Required)
'manage_options' ); // Page capability (Optional) [default is manage_options]
$settings->set_tabs ( array (
array (
jQuery( 'form.checkout, form#order_review' ).addClass("processing").block({
message: null ,
overlayCSS: {
background: "#fff",
opacity: .6
}
});
<?php
function odin_contact_author_form($author_id) {
$author_email = get_the_author_meta( 'user_email', $author_id );
$form = new Odin_Contact_Form(
'form_id', // ID do formulário
'eu@email.com', // E-mail do destinatário.
array( 'vc@email.com', 'tu@email.com', $author_email ), // array com e-mails que receberão cópia.
array( 'alguem@email.com' ) // array com e-mails que receberão cópia oculta.
// array( 'class' => 'form' ) // array com atributos para o formulário.
// 'file' // string com método que será enviado o anexo, no caso 'file' como anexo e 'url' para enviar links.
@matheuscl
matheuscl / post-views
Created March 24, 2015 18:34
Function to set post views and set cache.
<?php
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count == ""){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '1');
wp_cache_set( "view_" . $postID, TRUE, "", 0 );
}else{
<?php
function theme_name_scripts() {
if( is_user_logged_in() ){
wp_enqueue_style( 'style-logged-in', get_stylesheet_uri(). '/css/logged-in.min.css', array(), '1.0.0' );
}else{
wp_enqueue_style( 'style-logged-out', get_stylesheet_uri(). '/css/logged-out.min.css', array(), '1.0.0' );
}
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
@matheuscl
matheuscl / wp_permasctructs
Created February 23, 2015 20:21
Add custom Pretty Link to Custom Post Type or Custom Taxonomy
<?php
/**
* Add custom Pretty Link to Custom Post Type or Custom Taxonomy
*
* Change @@@ to your CPT or CT slug...
*
* Change ??? to custom link like example or anything else...
*
*/
function wp_permastructs(){
@matheuscl
matheuscl / reload_images
Created February 3, 2015 18:07
This function help when u need to add img after page load...
$.imgReload = function() {
var retries = 0;
var loaded = 1;
$("img").each(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
var src = $(this).attr("src");
var date = new Date();
$(this).attr("src", src + "?v=" + date.getTime()); //slightly change url to prevent loading from cache
loaded =0;
}
@matheuscl
matheuscl / custom_pagination.php
Last active March 29, 2017 20:18
WordPress custom pagination
<?php
/** Custom Pagination */
function custom_pagination($total_pages, $current_page, $pageByGet = true){
// Only paginate if we have more than one page
if ( $total_pages > 1 ) {
$big = 999999999;
// Structure of "format" depends on whether we’re using pretty permalinks