Len
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Post title char count?heh. I ran into this same problem when I redesigned my front page. Long post titles wrapped to the second line causing that content block to drop out of alignment with respect to the others.
The fix is simple enough – create a new function then call it in whatever template file you want.
Add this to your theme’s functions.php …
function trim_title() { $title = get_the_title(); $limit = "x"; $pad="..."; if(strlen($title) <= $limit) { echo $title; } else { $title = substr($title, 0, $limit) . $pad; echo $title; } }Adjust the line
$limit = "x";to whatever you want. (say 20 for example)Then look in the appropriate template file for
the_title()and replace with your new functiontrim_title()If your post title is more than the limit you specified it will trim it to that specification. If it is less it will do nothing.Forum: Fixing WordPress
In reply to: How do I only show summary on front page?Is there a way of controlling how many lines of excerpt I would like to display?
Yes. I just answered a similar question in another thread here.
Forum: Fixing WordPress
In reply to: Showing an image in the excerptGive Justin Tadlock’s Get the Image plugin a try. It will display thumbnails according to the custom field keys you set up. If no keys were set up then it will pull the first image from the post and use that.
I can show you a way to do it without a plugin but it requires a bit of work and this plugin is so much easier.
Forum: Fixing WordPress
In reply to: Homepage – Limiting number of postsThere are a couple of ways to accomplish this. Probably the easiest is simply to use the “more” button on the “write post toolbar”. The other option is to use excerpts.
Your home page currently uses the template tag
<?php the_content(); ?>so change that to<?php the_excerpt(); ?>When using excerpts WordPress will automatically pull the first 55 characters from your post and display that. If you want to change that add the following to your theme’s
functions.phpfile …remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_trim_excerpt'); function custom_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = x; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '...'); $text = implode(' ', $words); } } return $text; }Look for the line (from the above code)
$excerpt_length = x;and change x to whatever you want. This comes with a caveat – you will lose any formatting the post had but its not a big deal. If you want to maintain formatting while using<?php the_excerpt(); ?>then use the Excerpt box below the Write Post box. Anything you enter into this box will be used to display your excerpts.(summaries) Here is a screenshot to show you what I’m talking about.More reading on the_content and the_excerpt
Forum: Fixing WordPress
In reply to: How to show posts from same category as current post in sidebar?Place the following in sidebar.php or whatever file your theme uses to display the sidebar,
<?php global $post; $categories = get_the_category(); foreach ($categories as $category) : ?> <h3>More News From This Category</h3> <ul> <?php $posts = get_posts('numberposts=20&category='. $category->term_id); foreach($posts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> <li><strong><a href="<?php echo get_category_link($category->term_id);?>" title="View all posts filed under <?php echo $category->name; ?>">ARCHIVE FOR '<?php echo $category->name; ?>' CATEGORY »</a></strong></li> <?php endforeach; ?> </ul>This will display the titles of the most 20 recent entries of whatever category the post displayed on single.php belongs to.
In other words, someone arrives at the home page of your blog. They start reading a post about cars that belongs to the Automobile category. The click the title (or read more link or whatever) and arrive at the single post page (single.php) to finish reading the article. In the sidebar will be a list of the 20 most recent posts belonging to the Automobile category.
To change the number of titles displayed simply alter
numberposts=20Forum: Fixing WordPress
In reply to: Can someone help me decode footer?…the footer is decoded there. All you have to do is find the php that is the footer, copy it, and past it into the footer file replacing everything.
You can make it a little easier by wrapping the footer call so that the output stands out in the source view. For instance, look for
<?php wp_footer(); ?>and do something like,<!--EVIL FOOTER--> <?php wp_footer(); ?> <!--EVIL FOOTER-->When you view the source code simply copy/paste everything between those comments.
A large caveat: while this technique may work sometimes, it will not work all of the time. There may be PHP functions in the background that will NOT show up in the generated HTML. Same goes for javascript. Just so you know.
Anyway, you can view the decoded version of that nonsense here.
Forum: Themes and Templates
In reply to: Spring Time – A New Free ThemeI just installed that theme locally to see for myself. I see what you mean about the comment form showing but not the actual comments themselves. The fact that I can successfully do it in half dozen other themes I tested leads me to suspect a coding problem somewhere in the comments template file but I haven’t got the time to debug right now.
Edit: if you have the time you may want to carefully compare the comments template file of that theme to another such as the default theme
Forum: Plugins
In reply to: Removing Next and PreviousI knew you’d find it. Feels good to figure this stuff out on your own, yes? 🙂
Forum: Themes and Templates
In reply to: Spring Time – A New Free ThemeI see what you mean. Try renaming
page-comments.phptopage_comments.phpthen reselect/reassign whatever page you want to use that template file.Forum: Fixing WordPress
In reply to: How can I change how archived and categorized materials display?archive.phpis the file you want.More reading on the_content() and the_excerpt()
Forum: Fixing WordPress
In reply to: How can I change how archived and categorized materials display?I’ll have a look at the theme.
Forum: Plugins
In reply to: Removing Next and PreviousIt probably exists in other files in addition to
index.phpForum: Your WordPress
In reply to: Recover password not workingI’ve seen this error before and am not sure what causes it. If you can access your database via phpMyAdmin you can change it right there. Mark has an easy to follow guide here.
Be careful when proceeding. You will be interacting directly with the database. There is no “undo”.
Forum: Fixing WordPress
In reply to: How can I change how archived and categorized materials display?I’m not familiar with the theme but I assume it is using
the_content()Just change that template tag to
the_excerpt()By default, when using
the_excerpt()WordPress will display the first 55 characters from your post. If you want to alter that place this in your theme’sfunction.phpfile,remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_trim_excerpt'); function custom_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = x; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '...'); $text = implode(' ', $words); } } return $text; }Adjust the line
$excerpt_length = x;to whatever you want.Forum: Fixing WordPress
In reply to: Comment SpamDo you have Akismet installed/activated? You might also want to check out Bad Behaviour. It blocks many malicious bots from even accessing your site which is a good thing since most spam is auto-generated from bots/scripts.