Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Last active September 28, 2016 02:35
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 ericnicolaas/dd373a615d2a4c29642460fd4181bf6b to your computer and use it in GitHub Desktop.
Save ericnicolaas/dd373a615d2a4c29642460fd4181bf6b to your computer and use it in GitHub Desktop.
Reach - Display a single campaign on the homepage
<?php
/**
* Template name: Campaign Page
*/
get_header();
?>
<main id="main" class="site-main site-content cf" role="main">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
/**
* @var Charitable_Campaign
*/
$campaign_id = get_post_meta( get_the_ID(), 'campaign', true );
endwhile;
endif;
if ( $campaign_id ) :
$post = get_post( $campaign_id );
setup_postdata( $post );
$campaign = charitable_get_campaign( $post );
if ( ! $campaign->is_endless() ) {
/**
* Include this to properly enqueue the countdown scripts.
*/
wp_enqueue_script( 'countdown-plugin', get_template_directory_uri() . '/js/vendors/jquery-countdown/jquery.plugin.min.js', array( 'jquery' ), reach_get_theme()->get_theme_version(), true );
wp_enqueue_script( 'countdown', get_template_directory_uri() . '/js/vendors/jquery-countdown/jquery.countdown.min.js', array( 'countdown-plugin' ), reach_get_theme()->get_theme_version(), true );
}
/**
* @hook charitable_single_campaign_before
*/
do_action( 'charitable_single_campaign_before', $campaign );
?>
<div class="layout-wrapper">
<div id="primary" class="content-area <?php if ( ! is_active_sidebar( 'sidebar_campaign' ) ) : ?>no-sidebar<?php endif ?>">
<?php
/**
* @hook charitable_campaign_content_before
*/
do_action( 'charitable_campaign_content_before', $campaign );
get_template_part( 'partials/content', 'campaign' );
/**
* @hook charitable_campaign_content_after
*/
do_action( 'charitable_campaign_content_after', $campaign );
?>
</div><!-- #primary -->
<?php get_sidebar( 'campaign' ) ?>
</div><!-- .layout-wrapper -->
<?php
/**
* @hook charitable_single_campaign_after
*/
do_action( 'charitable_single_campaign_after' );
endif;
?>
</main><!-- #main -->
<?php
get_template_part( 'partials/campaign', 'share-modal' );
get_footer();
@ericnicolaas
Copy link
Author

To use this template, drop it into the Reach child theme inside a folder called page-templates (you might need to create this).

Then, create a page and select the "Campaign Page" template.

The final step is to nominate the campaign to display. Do this by scrolling to the Custom Fields section (if you don't see it, click on Screen Options and tick Custom Fields) and adding a new custom field with a name of "campaign" and a value of the ID of the campaign. In the example pictured below, we are displaying the campaign with ID 20:

screenshot 2016-04-28 22 09 07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment