Skip to content

Instantly share code, notes, and snippets.

Avatar

Nuno Morais Sarmento nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / acf-postobject-repeater.php
Created Apr 26, 2017
ACF: Get Post Object data within a Repeater
View acf-postobject-repeater.php
<section class="slider">
<?php if( have_rows('slides') ): ?>
<div id="slider" class="flexslider">
<ul class="slides">
<?php while ( have_rows('slides') ) : the_row(); ?>
@nfsarmento
nfsarmento / is_blog.php
Created Aug 9, 2017 — forked from wesbos/is_blog.php
WordPress is_blog()
View is_blog.php
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@nfsarmento
nfsarmento / simple-map-defer.php
Created Dec 12, 2017 — forked from glueckpress/simple-map-defer.php
[WordPress][Simple Map] Load Google Maps API script from Simple Map deferred.
View simple-map-defer.php
<?php
defined( 'ABSPATH' ) or die( 'No direct access here.' );
/**
* Plugin Name: Simple Map | Defer
* Description: Makes sure Google Maps API script from <a href="https://wordpress.org/plugins/simple-map/">Simple Map</a> gets loaded deferred.
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress
* Plugin URI: https://gist.github.com/glueckpress/56c88900aad391b95b5d44f4e752a1a4
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
@nfsarmento
nfsarmento / php7.1.md
Last active Jan 31, 2018 — forked from VirtuBox/php7.1.md
How to install php7.1-fpm with EasyEngine
View php7.1.md

How to install php7.1-fpm with EasyEngine


Install php7.1-fpm

apt install php7.1-common php7.1-cli php7.1-zip php7.1-opcache php7.1-mysql php7.1-mcrypt php7.1-mbstring php7.1-json php7.1-intl php7.1-gd php7.1-fpm php7.1-curl php7.1-bz2

Copy the php7.1-fpm pool configuration from php7.0-fpm

cp -f /etc/php/7.0/fpm/pool.d/www.conf /etc/php/7.1/fpm/pool.d/www.conf
@nfsarmento
nfsarmento / a-theme-auth.php
Created Jan 31, 2018 — forked from itzikbenh/a-theme-auth.php
WordPress class for registering users via Linkedin
View a-theme-auth.php
<?php
function a_theme_auth_options_page()
{
add_options_page( "A-Theme Auth options", "A-Theme Auth", "manage_options", "a-theme-auth", "a_theme_auth_options" );
}
add_action( 'admin_menu', 'a_theme_auth_options_page' );
function register_a_theme_auth_settings()
{
@nfsarmento
nfsarmento / ajax-filter-posts.js
Created Mar 11, 2018
Ajax filters for CPT with custom taxonomy
View ajax-filter-posts.js
(function($) {
'use strict';
jQuery(document).ready(function() {
//Load all posts
asr_ajax_get_postdata(-1);
$('.asr_texonomy').on('click',function(){
var term_id = $(this).attr('data_id');
@nfsarmento
nfsarmento / content-reports.php
Created Mar 11, 2018
CPT metabox check option to show CPT post on page template
View content-reports.php
<article <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>">
<header class="heading-cpt">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail( 'full' );
}
?>
View Get image url outside loop
<?php
$page_id = get_queried_object_id();
$post_thumbnail_id = get_post_thumbnail_id( $page_id );
$bkgdImg = wp_get_attachment_url( $post_thumbnail_id );
echo $bkgdImg;
?>
View Add colours pallete to WordPress visual editor
function ns_mce4_options($init) {
$custom_colours = '
"3366FF", "Color 1 name",
"CCFFCC", "Color 2 name",
"FFFF00", "Color 3 name",
"99CC00", "Color 4 name",
"FF0000", "Color 5 name",
"FF99CC", "Color 6 name",
"CCFFFF", "Color 7 name"
@nfsarmento
nfsarmento / bootstrap 4 collapse accordion with ACF repeater.php
Last active Mar 22, 2018
bootstrap 4 collapse accordion with ACF repeater
View bootstrap 4 collapse accordion with ACF repeater.php
<?php if( have_rows('collapse') ): ?>
<div id="accordion" role="tablist">
<?php $i=1; while ( have_rows('collapse') ) : the_row(); ?>
<div class="card">
<div class="card-header" role="tab" id="heading-<?php echo $i; ?>">
<h5 class="mb-0">
<a data-toggle="collapse" href="#collapse-<?php echo $i; ?>" aria-expanded="true" aria-controls="collapseOne">
<?php the_sub_field('title'); ?>
</a>
</h5>
You can’t perform that action at this time.