Forum Replies Created

Viewing 15 replies - 241 through 255 (of 1,218 total)
  • 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 function trim_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.

    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.

    Give 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.

    There 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.php file …

    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

    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 &raquo;</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=20

    …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.

    I 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 Previous

    I knew you’d find it. Feels good to figure this stuff out on your own, yes? 🙂

    I see what you mean. Try renaming page-comments.php to page_comments.php then reselect/reassign whatever page you want to use that template file.

    archive.php is the file you want.

    More reading on the_content() and the_excerpt()

    I’ll have a look at the theme.

    Forum: Plugins
    In reply to: Removing Next and Previous

    It probably exists in other files in addition to index.php

    I’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”.

    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’s function.php file,

    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 Spam

    Do 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.

Viewing 15 replies - 241 through 255 (of 1,218 total)