Skip to content

Instantly share code, notes, and snippets.

View emaildano's full-sized avatar
🏄‍♀️
Surfing the information superhighway

Dano emaildano

🏄‍♀️
Surfing the information superhighway
  • Philadelphia, PA
View GitHub Profile
<?php
// Layout Option: Table via Tablepress
// Init Post Object
$postobject = get_sub_field('table');
$post = $postobject;
setup_postdata( $post );
// tablepress plugin query / args
// get ACF saved data.
@emaildano
emaildano / acf-field-counter.php
Created May 28, 2014 20:15
ACF field counter snippet.
<?php
// get the count on the repeater field
// mabye use get_sub_field() instead of get_field() if it's nested
$count = count( get_sub_field( 'the_field' ) );
// begin $count conditions
if ( $count > 1 ) { ?>
// greater than 1
<?php the_field( 'great_than_1' ); ?>
<?php } else { ?>
@emaildano
emaildano / container-fluid-color-wrap-repeater.php
Last active August 29, 2015 14:01
Started code for bootstrap columns container / container-fluid full backgrounds.
<?php if( have_rows('images') ): ?>
<div class="container">
<div class="row">
<section class="image-row">
<div class="color-wrap">
<?php while ( have_rows('images') ) : the_row(); ?>
<div class="half" style="background-color:<?php the_sub_field('background_color'); ?>"></div>
<?php endwhile; ?>
</div>
@emaildano
emaildano / accordion-php.php
Created May 7, 2014 14:40
Starter for styled bootstrap panels.
<?php if(get_sub_field('accordion_section')) : $i = 0; ?>
<section class="panels-wrapper">
<?php while(has_sub_field('accordion_section')) : $i++; ?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<?php
// panel link conditions
@emaildano
emaildano / right-left-flexible-content.php
Created May 6, 2014 21:11
Starter for creating a left / right independent columns.
<?php
// Two Column Repeater to hold Left / Right Flexible Content Fields
if( have_rows('two_col_row') ): while ( have_rows('two_col_row') ) : the_row(); ?>
<?php
// left col flexible content
while(has_sub_field("left_column")): ?>
<?php if(get_row_layout() == "body_copy"): // layout: Content ?>
<?php the_sub_field('title'); ?>
<?php the_sub_field('body_copy'); ?>
@emaildano
emaildano / group-posts-by-cat.php
Last active August 29, 2015 14:00
Group blog posts by category boilerplate.
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id; ?>
<h2><?php echo $cat->name ?></h2>
@emaildano
emaildano / tag-comma-list.php
Last active August 29, 2015 13:59
Get tags as commas list
<?php
// post tags
$posttags = get_the_tags();
if ($posttags) {
$taglist = ""; ?>
<ul class="tags">
<div class="title">Tags</div>
<?php foreach($posttags as $tag) {
$taglist .= '<a href="'. get_tag_link($tag->term_id) .'">' . $tag->name . '</a>, ';
} echo rtrim($taglist, ", "); } ?>
@emaildano
emaildano / get-first-flexible-content-field.php
Created April 11, 2014 18:50
Get the first sub-field from a flexible content field.
<?php
// If the page has Flexible Content:
if(get_field('flexible_main_content')) :
$rows = get_field('flexible_main_content');
// Get the first instance of the Body Copy field
foreach( array_slice($rows, 0, 1) as $row ) {
$excerpt = $row['body_copy'];
echo '<p>' . trunc($excerpt, 15) . '</p>';
}
// Otherwise get the content
@emaildano
emaildano / word-limit-function.php
Last active August 29, 2015 13:59
Limit by word count excerpts.
// Limit Word Count, Strip Tags from Result
function trunc($phrase, $max_words) {
$phrase_array = explode(' ',strip_tags($phrase));
if(count($phrase_array) > $max_words && $max_words > 0)
;
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...';
return $phrase;
}
@emaildano
emaildano / get-tax-without-link.php
Last active August 29, 2015 13:58
List custom taxonomies without links.