Support » Fixing WordPress » title with post content

  • hi, this is my first post and im very happy:)

    with “<?php get_archives(‘postbypost’, 15); ?>” i can add the last 15 posts to sidebar.

    i want also add a few words from content to title for giving some idea about the post.

    Cheetas the FastestThey can run 80 km…
    (post title)(a few words from top of post content)

    how can i do it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • i also searched codex, but found nothing

    You could go the plugin route. Pick one from this list:

    Or you could make WordPress do it without plugins (it is possible). If you want to do more than just list the titles of recent posts, you don’t want to use get_archives. If you look in your Main Index Template, you should find all the code that displays your recent entries on your home page. Take that and paste it into your sidebar; copy everything between <?php while (have_posts()) : the_post(); ?> and <?php endwhile; ?> and paste it into your sidebar. It’s the_content you want to limit, so that it only displays the first few words of each entry. You’ll also probably want to change the way all the entries display, so you’ll need to change some code around. That should get you started, though.

    To limit the_content

    You could try this method (taking advantage of a feature that’s already built into WordPress):

    From the Codex:

    There are also plugins that allow this same feature without needing to insert any quicktags: (check the versions they work on) (not sure if it works with WP 2.5.1)

    This looks interesting:

    I found all this by doing a quick Google search for “limit the_content wordpress” so see if that works any better for you.

    really thanks for your large message, but they all about content in main area,
    im talking about just sidebar, last messages, main area isnt problem, i dont concern “read more” tag

    these codes much closer what i say, but i dont know how edit it for just sidebar

    function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
       if (strlen($_GET['p']) > 0) {
          echo $content;
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo $content;
            echo "<a href='";
            echo "'>"."..."."</a>";
            echo "";
            echo "<a href='";
            echo "'>".$more_link_text."</a>
       else {
          echo $content;

    my sidebar:

  • <h2>Last Posts</h2>
    <?php get_archives(‘postbypost’, 15); ?>
    –> if i can add a function here that explain each messages with a few words, it will perfect.

You can put the_content in your sidebar. The links I gave you aren’t necessarily about the “read more” links; you could just as easily choose not to include such links. You can have the_content in the main blog area as well as in your sidebar. The get_archives function is very limited and won’t allow you to do what you want:

What I gathered from your original post is that you want to have something in your sidebar just like most people have on their home page: titles and the first, say, 50 characters of the latest 5 posts. I suggest that you simply take the code most people use on their home page and paste it into your sidebar.

Did you try to paste all that PHP you copied in your last message into the sidebar of your blog? What happened when you tried that? How do you know that code doesn’t do exactly what you want it to? What do you mean by “edit it for just sidebar”? If you can post results of your experiments, what works and what doesn’t, that’ll make it much easier to help.

Another thread posted something similar to this and it might get you closer to what you want:

<?php $myposts = get_posts('numberposts=5&offset=0');
foreach($myposts as $post); ?>
<?php $thumbnail = get_post_meta($post->ID, 'post_thumb', true); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> - <?php the_content_limit(100, "..."); ?></a></li>
<?php endforeach; ?>

I haven’t tested it, but paste that in sidebar.php and you’ll probably get what you’re asking for.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘title with post content’ is closed to new replies.