Last active
November 2, 2015 06:02
-
-
Save bryanwillis/752e6c5fccec8c3e4389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//uses single template but not as good for theme compatability | |
<?php | |
function custom_template_snippet_post_type_plugin( $single ) { | |
global $wp_query, $post; | |
if ($post->post_type == "sdr_snippet"){ | |
// if in subfolder | |
$template = plugin_dir_path( __FILE__ ) . 'templates/single-snippet.php'; | |
// if in plugin root directory folder | |
//$template = plugin_dir_path( __FILE__ ) . '/single-snippet.php'; | |
// directory folder file | |
//$template = dirname( __FILE__ ) . '/single-snippet.php'; | |
if(file_exists( $template )) | |
return $template; | |
} | |
return $single; | |
} | |
add_filter('single_template', 'custom_template_snippet_post_type_plugin'); | |
?> | |
// THEN SINGLE WOULD LOOK SOMETHING LIKE THIS | |
<?php | |
function print_snippet_single_post() { | |
$language = sdr_snippet_get_language( get_the_ID() ); | |
$html = ''; | |
$html .= '<div class="sdr-snippet-container" data-language="' . esc_attr( $language ) . '" data-show-lines="true" data-height="0">'; | |
$html .= '<pre class="sdr-snippet-box">'; | |
$html .= esc_html( get_the_content() ); | |
$html .= sdr_enqueue_frontend(); | |
$html .= '</pre>'; | |
$html .= '</div>'; | |
return $html; | |
} | |
get_header(); | |
echo print_snippet_single_post(); | |
get_footer(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( $post = get_post( $page_id ) ) { | |
setup_postdata( $post ); // "posts" page is now current post for most template tags | |
the_content(); | |
wp_reset_postdata(); // So everything below functions as normal | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS WAY WORKS FOR SURE | |
<?php | |
function print_snippet_single_post($content) { | |
$postid = get_the_ID(); | |
$post_type = get_post_type( $postid ); | |
if ( is_singe( $postid ) ){ | |
if (have_posts()) : | |
the_post(); | |
// echo sdr_do_shortcode_snippet( $atts ); | |
$language = sdr_snippet_get_language( $postid ); | |
$html = ''; | |
$html .= '<div class="sdr-snippet-container" data-language="' . esc_attr( $language ) . '" data-show-lines="true" data-height="0">'; | |
$html .= '<pre class="sdr-snippet-box">'; | |
$html .= esc_html( get_the_content() ); | |
$html .= '</pre>'; | |
$html .= '</div>'; | |
if ( $post_type == "sdr_snippet") { | |
return $html; | |
} | |
else { | |
return $content; | |
} | |
endif; | |
} | |
// wp_reset_postdata(); | |
} | |
add_filter( 'the_content', 'print_snippet_single_post', 10 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print_snippet_single_post($content) { | |
$post_type = get_post_type( get_the_ID() ); | |
$language = sdr_snippet_get_language( get_the_ID() ); | |
$html = ''; | |
$html .= '<div class="sdr-snippet-container" data-language="' . esc_attr( $language ) . '" data-show-lines="true" data-height="0">'; | |
$html .= '<pre class="sdr-snippet-box">'; | |
$html .= esc_html( get_the_content() ); | |
$html .= '</pre>'; | |
$html .= '</div>'; | |
if ( $post_type == "sdr_snippet") { | |
return $html; | |
} | |
else { | |
return $content; | |
} | |
} | |
add_filter( 'the_content', 'print_snippet_single_post', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment