Skip to content

Instantly share code, notes, and snippets.

@jgraffin
Created June 8, 2016 17:34
Show Gist options
  • Save jgraffin/e5376c42575e44302cea442d15896151 to your computer and use it in GitHub Desktop.
Save jgraffin/e5376c42575e44302cea442d15896151 to your computer and use it in GitHub Desktop.
<?php
function footer_scripts() {
if(is_page('faca-sua-parte-dicas-de-como-votar-bem')) {
wp_enqueue_script( 'filter', get_stylesheet_directory_uri() . '/dist/assets/myDev/js/view/dicas.js', array(), null, true );
}
wp_localize_script( 'filter', 'wpAjax', array( 'ajaxurl'=>admin_url('admin-ajax.php') ) );
}
add_action( 'wp_enqueue_scripts', 'footer_scripts', 1 );
function taxonomy_category( $content = null ){
$dicas = get_terms( 'category' );
$displayList = '<div class="Tips-filter">';
$displayList .= '<div class="Tips-filterDropdown dropdown">';
$displayList .= '<button class="Tips-filterDropdown--button" id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Filtrar';
$displayList .= '<span class="Tips-filterDropdown--icon">';
$displayList .= file_get_contents(get_template_directory_uri() . '/dist/assets/myDev/image/icons/icon-arrow-down.svg');
$displayList .= '</span>';
$displayList .= '</button>';
$displayList .= '<ul class="Tips-filterDropdown--list dropdown-menu" aria-labelledby="dLabel">';
foreach( $dicas as $dica ){
$displayList .= '<li>';
$displayList .= '<a href="#" data-filter="'. $dica->slug .'">' . $dica->name . $dica->count . '</a>';
$displayList .= '</li>';
}
$displayList .= '</ul>';
$displayList .= '</div>';
$displayList .= '</div>';
return $displayList;
}
add_shortcode( 'cat_dicas', 'taxonomy_category' );
function dicasCat_callback(){
$term_slug = $_POST[ 'term-slug' ];
$item = array();
$args = array(
'post_type' => 'dicas',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $term_slug
)
)
);
query_posts( $args );
if(have_posts()):
while(have_posts()): the_post();
$url_page = get_field('url_page');
$link_page = get_field('link_page');
$name_button = get_field('name_button');
$post = get_post( get_the_ID() );
$item['html'] = '<div class="Tips-block">';
$item['html'] .= '<div class="CardCategory-category">';
$item['html'] .= '<a href="' . $link_page . '" target="_blank">';
$item['html'] .= get_queried_object()->name;
$item['html'] .= '</a>';
$item['html'] .= '</div>';
$item['html'] .= '<div class="CardCategory-container">';
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'tips' );
if(!empty($thumbnail)):
$item['html'] .= '<div class="CardCategory-image">';
$item['html'] .= '<a href="' . $link_page . '" target="_blank">';
$item['html'] .= '<img src="' . $thumbnail['0'] . '" />';
$item['html'] .= '</a>';
$item['html'] .= '</div>';
endif;
$item['html'] .= ' <div class="CardCategory-title">';
$item['html'] .= '<a href="' . $link_page . '" target="_blank">';
$item['html'] .= $post->post_title;
$item['html'] .= '</a>';
if(!empty($url_page)):
$item['html'] .= '<a href="' . $link_page . '" target="_blank">';
$item['html'] .= '<strong>' . $url_page . '</strong>';
$item['html'] .= '</a>';
endif;
$item['html'] .= '</div>';
$item['html'] .= '<div class="CardCategory-text">';
$item['html'] .= $post->post_content;
$item['html'] .= '</div>';
$item['html'] .= '<div class="CardCategory-links">';
$item['html'] .= '<div class="Share">';
$item['html'] .= '<div class="Share-list">';
$item['html'] .= '<div class="Share-listItem Share-listItem--facebook">';
$item['html'] .= '<div class="fb-share-button" data-href="' . $post->post_title . ": " . $url_page . '" target="_blank"></div>';
$item['html'] .= '</div>';
$item['html'] .= '<div class="Share-listItem">';
$partial_url = 'https://twitter.com/intent/tweet?text=';
$item['html'] .= '<a class="twitter-share-button" href="' . $partial_url . $post->post_title . ": " . $url_page . '" target="_blank">';
$item['html'] .= '</div>';
$item['html'] .= '</div>';
$item['html'] .= '</div>';
$item['html'] .= '<a class="ButtonAction ButtonAction--Blue" href="' . $link_page . '" target="_blank">';
$item['html'] .= $name_button;
$item['html'] .= '</a>';
$item['html'] .= '</div>';
$item['html'] .= '</div>';
endwhile;
endif;
echo json_encode($item);
wp_die();
}
add_action( 'wp_ajax_dicasCat', 'dicasCat_callback' );
add_action( 'wp_ajax_nopriv_dicasCat', 'dicasCat_callback' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment