seanjacob
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Limit excerpt length by charactersHaha nice one! No problem.
Forum: Fixing WordPress
In reply to: Limit excerpt length by charactersWithout the truncating –
function get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>'; return $excerpt; }
Forum: Fixing WordPress
In reply to: Limit excerpt length by charactersUse this function if you’re planning on using it more than once with a different amount of characters.
function get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>'; return $excerpt; }
Call the function plus the amount of characters –
<?php echo get_excerpt(125); ?>
Forum: Fixing WordPress
In reply to: Limit excerpt length by characters$permalink = get_permalink($post->ID);
Try adding this to the top of the function.
Thank you Edd! The is exactly what I was looking for, there should be a detailed list for what every type does.
Forum: Fixing WordPress
In reply to: How to display non related posts after related posts?I ended up doing it the long way, let me if you find better.
<?php $the_cat = get_the_category(); $cat_id = $the_cat[0]->cat_ID; $c = 0; $the_query = new WP_Query(array('post__not_in' => array($id), 'orderby' => 'rand', 'posts_per_page' => 2, 'tag' => 'Omega,Seamaster')); if( have_posts() ) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <div class="featured-article"> <img src="<?php echo wp_get_attachment_url(get_post_meta($post->ID, 'banner', true)); ?>" /> <h3 class="featured-article-title"><?php the_title() ?></h3> <h4 class="featured-article-details"><?php if(get_the_author_id() != 5) { ?>written by <?php the_author(); ?> - <?php } else { ?>Posted <?php } ?><?php the_time('jS M Y'); ?></h4> <?php echo get_excerpt(50); ?> <?php $c++ ?> <?php $last_post = $post->ID; ?> </div> <?php endwhile; wp_reset_postdata(); endif; ?> <?php $i = 2-$c; if ($i > 0){ $the_query = new WP_Query(array('category__in' => $cat_id, 'post__not_in' => array($id, $last_post), 'orderby' => 'rand', 'posts_per_page' => $i)); if( have_posts() ) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <div class="featured-article"> <img src="<?php echo wp_get_attachment_url(get_post_meta($post->ID, 'banner', true)); ?>" /> <h3 class="featured-article-title"><?php the_title() ?></h3> <h4 class="featured-article-details"><?php if(get_the_author_id() != 5) { ?>written by <?php the_author(); ?> - <?php } else { ?>Posted <?php } ?><?php the_time('jS M Y'); ?></h4> <?php echo get_excerpt(50); ?> </div> <?php endwhile; wp_reset_postdata(); endif; ?> <?php } ?>
Forum: Fixing WordPress
In reply to: Limit excerpt length by characters$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
Replace this line in my code with –
$excerpt = '<p>'.$excerpt.'... <a href="'.$permalink.'">more</a></p>';
Forum: Fixing WordPress
In reply to: Limit excerpt length by charactersGlad you found a solution. My code doesn’t truncate the last word either and with my problem I needed it to be by characters not words.
Forum: Fixing WordPress
In reply to: Limit excerpt length by charactersIn functions.php add
function get_excerpt(){ $excerpt = get_the_content(); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, 40); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>'; return $excerpt; }
Change the value 40 to how many characters you want to display. And also ‘more’ to what text you want to display.
Then call your function in index.php or where ever your planning on getting your posts.
<?php echo get_excerpt(); ?>
Forum: Fixing WordPress
In reply to: Comments unapproved self?Whoops should have got back to this. I have now solved the issue. Thank you esmi.
Yes deactivating all the plugins is the first step I always take but as the problem randomly happens its hard to test.
But I eventually figured out it was my report comment plugin of course!
Is this going to be a update to fix this problem? I don’t even have anything in my function to get my custom fields and I am having the same problem…
Forum: Plugins
In reply to: [Custom Field Template] Media Picker broken in 1.9?likewise.
shoot my bad! It will not work for existing posts. Sorry I am a noob to your superb plugin.
I am also trying to get a default/value in my text field but doesn’t seem to be working for me am I doing anything wrong? Also should the default appear in the field or be blank but still contains the value.
[summary_title] label = Summary title type = text default = In summary output = true
This is a good article.
https://www.kevinleary.net/advanced-content-management-wordpress-custom-field-templates/