Skip to content

Instantly share code, notes, and snippets.

@nicholasdixon
Created January 16, 2016 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasdixon/9842351b316597d3e782 to your computer and use it in GitHub Desktop.
Save nicholasdixon/9842351b316597d3e782 to your computer and use it in GitHub Desktop.
Working Excerpt with Custom Posts
<?php
// Set varable for getting the excert of the custom post
$my_excerpt = get_the_excerpt();
// Sets the number of posts to display, if it is the front page (home), then 4 posts show, if not then all posts show.
$num_posts = ( is_front_page() ) ? 4 : -1;
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $num_posts
);
$query = new WP_Query( $args );
?>
<section class="row no-max pad">
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<div class="small-6 medium-4 large-3 columns grid-item">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h3>
<?php the_post_thumbnail('large'); ?></a>
<!-- Echoing the varable that holds the excerts of the custom posts -->
<a href="<?php the_permalink(); ?>"><?php echo $my_excerpt; ?></a>
</div>
<?php endwhile; endif; wp_reset_postdata(); ?>
</section>
<?php
add_theme_support( 'menus' );
add_theme_support( 'post-thumbnails' );
// Controls the length of the Posts and Custom Posts
function wpt_excerpt_length( $length ) {
return 26;
// return 16;
}
add_filter( 'excerpt_length', 'wpt_excerpt_length', 999 );
function register_theme_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu', 'treehouse-portfolio' )
)
);
}
add_action( 'init', 'register_theme_menus' );
function wpt_create_widget( $name, $id, $description ) {
register_sidebar(array(
'name' => __( $name ),
'id' => $id,
'description' => __( $description ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="module-heading">',
'after_title' => '</h2>'
));
}
wpt_create_widget( 'Page Sidebar', 'page', 'Displays on the side of pages with a sidebar' );
wpt_create_widget( 'Blog Sidebar', 'blog', 'Displays on the side of pages in the blog section' );
function wpt_theme_styles() {
wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css' );
//wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css' );
wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );
function wpt_theme_js() {
wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'), '', true );
wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true );
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_js' );
?>
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php get_header(); ?>
<section class="row">
<div class="small-12 columns text-center">
<div class="leader">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
</section>
<?php get_template_part('content', 'portfolio'); ?>
<?php get_footer(); ?>
<?php get_header(); ?>
<section class="two-column row no-max pad">
<div class="small-12 columns">
<div class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Primary Column -->
<div class="small-12 medium-7 medium-offset-1 medium-push-4 columns">
<div class="primary">
<!-- Change so it is the same name as the custom field, be carefull is it images or image -->
<?php the_field('image'); ?>
</div>
</div>
<!-- Secondary Column -->
<div class="small-12 medium-4 medium-pull-8 columns">
<div class="secondary">
<h1><?php the_title(); ?></h1>
<p><?php the_field('description'); ?></p>
<hr>
<p>
<?php previous_post_link(); ?> -
<!-- the following code adds a link back to the portfolio page -->
<a href="<?php bloginfo('url'); ?>/portfolio">Back to Portfolio</a> -
<?php next_post_link(); ?>
</p>
</div>
</div>
<?php endwhile; endif; ?>
</div>
</section>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment