Created
November 17, 2011 21:04
-
-
Save carlynorama/1374521 to your computer and use it in GitHub Desktop.
Create a more tag when it doesn't exist in a Wordpress Twenty Eleven Theme
This file contains 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 | |
//functions that need to be in the functions.php | |
//for this to work | |
//more tag detection | |
function has_more() | |
{ | |
global $post; | |
if ( empty( $post ) ) return; | |
if ($pos=strpos($post->post_content, '<!--more-->')) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function more_posistion() | |
{ | |
if ($pos=strpos($post->post_content, '<!--more-->')) { | |
return $pos; | |
} | |
} | |
///limit content length | |
//http://www.fusedthought.com/archives/wordpress-custom-content-length-code-snippet | |
function limit_content($content_length = 150, $allowtags = true, $allowedtags = '') { | |
global $post; | |
$content = $post->post_content; | |
$content = apply_filters('the_content', $content); | |
if (!$allowtags){ | |
$allowedtags .= '<style>'; | |
$content = strip_tags($content, $allowedtags); | |
} | |
$content = str_replace(']]>', ']]>', $content); | |
$wordarray = explode(' ', $content, $content_length + 1); | |
if(count($wordarray) > $content_length) : | |
array_pop($wordarray); | |
array_push($wordarray, '...'); | |
$content = implode(' ', $wordarray); | |
$content .= "</p>"; | |
$content .= twentyeleven_continue_reading_link(); | |
endif; | |
echo $content; | |
} | |
?> |
This file contains 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
//content index is a copy of content-images.php from the twenty-eleven theme | |
//I changed the section referencing the content | |
<div class="entry-content"> | |
<?php if (has_more()) { | |
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); | |
} else { | |
$my_content = limit_content(); | |
echo $my_content; | |
}?> | |
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?> | |
</div><!-- .entry-content --> |
This file contains 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 | |
//what is now | |
global $more; | |
$more = 0; | |
$format = get_post_format( $post_id ); | |
if ( ! $format ) { | |
get_template_part( 'content', 'index' ); | |
} else { | |
get_template_part( 'content', get_post_format() ); | |
} | |
?> |
This file contains 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 | |
//what it used to be | |
global $more; | |
$more = 0; | |
get_template_part( 'content', get_post_format() ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment