carlynorama
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Excerpt if there is no more tag? REVISTEDActually… even better…
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() ); }Forum: Fixing WordPress
In reply to: Custom excerpt length doesn't work anymoreBug Fix – showcase.php stopped working when i moved it live, the following change fixed it:
if ( has_post_format()) {to
if ( has_post_format('')) {I have no idea why it worked on my local dev and not on my live site. They are supposed to be identical.
Forum: Fixing WordPress
In reply to: Excerpt if there is no more tag? REVISTEDOh, a note – once I moved the code from the test server to live server it broke until I changed
if ( has_post_format()) {to
if ( has_post_format('')) {I have no idea why it worked on my local dev and not on my live site. They are supposed to be identical.
Forum: Fixing WordPress
In reply to: Excerpt if there is no more tag? REVISTEDJust because this took me hours to sort out – I just posted my solution to this to another thread about custom excerpt lengths because I was having trouble getting those to show (resolved, http://wordpress.org/support/topic/custom-excerpt-length-doesnt-work-anymore ).
My fix in the end was Instead of using the_excerpt if there isn’t a more tag, I’m doing a custom function to get a content at an arbitrary length.
I’m using a child theme of twenty eleven, hence the
$content .= twentyeleven_continue_reading_link();at the end.in my showcase.php
// Set $more to 0 in order to only get the first part of the post. global $more; $more = 0; if ( has_post_format()) { get_template_part( 'content', get_post_format() ); } else { get_template_part( 'content', 'index' ); }In my content-index.php
<?php if (has_more()) { the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); } else { $my_content = limit_content(); //$my_content = apply_filters('the_content', $my_content); //$my_content = str_replace(']]>', ']]>', $my_content); echo $my_content; }?>in the functions.php
//more tag detection //http://wordpress.org/support/topic/check-if-post-has-more 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; }other relevant pages:
http://codex.wordpress.org/Customizing_the_Read_More (“Displaying a “more…” link without a <–more–> tag”)Forum: Fixing WordPress
In reply to: Custom excerpt length doesn't work anymoreI knew there was some giant known-quantity that I was missing. I was unclear on what that section meant. Thank you. I will read more about how child themes interact with the parent, for sure.
I found a work around though, that I might like better. It is sort of an “auto more function”
in my showcase.php
// Set $more to 0 in order to only get the first part of the post. global $more; $more = 0; if ( has_post_format()) { get_template_part( 'content', get_post_format() ); } else { get_template_part( 'content', 'index' ); }In my content-index.php
<?php if (has_more()) { the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); } else { $my_content = limit_content(); //$my_content = apply_filters('the_content', $my_content); //$my_content = str_replace(']]>', ']]>', $my_content); echo $my_content; }?>in the functions.php
//more tag detection //http://wordpress.org/support/topic/check-if-post-has-more 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; }other relevant pages:
http://codex.wordpress.org/Customizing_the_Read_More (“Displaying a “more…” link without a <–more–> tag”)Forum: Fixing WordPress
In reply to: Custom excerpt length doesn't work anymoreI’m sorry, but I am also having this trouble.
Using a twenty eleven child them, Ive added the following to my functions.php to no avail.
remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); function new_excerpt_length($length) { return 10; } add_filter('excerpt_length', 'new_excerpt_length');The Excerpt Length Plugin doesn’t work.
using the
get_the_excerptcall in my content.php template instead doesn’t work.the example code in this support doesn’t work for me:
http://wordpress.org/support/topic/changing-length-of-the_excerpt-without-changing-it-on-the-whole-wordpress?replies=14The example code from the support topic below does – but it seems like the nuclear option:
http://wordpress.org/support/topic/changing-the-default-length-of-the_excerpt-1Any thoughts?
Forum: Themes and Templates
In reply to: Excerpt lengthI’m having the same trouble.
Twenty Eleven Theme, WordPress 3.2.1, adding
remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); function new_excerpt_length($length) { return 10; } add_filter('excerpt_length', 'new_excerpt_length');to functions.php gives me no love when I use
the_excerpt()Did this get resolved?
[duplicate: http://wordpress.org/support/topic/custom-excerpt-length-doesnt-work-anymore?replies=4 – please ask your question in one topic only – closed]