WordPress.org

Ready to get started?Download WordPress

Forums

title with post content (6 posts)

  1. turko
    Member
    Posted 6 years ago #

    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.

    example:
    Cheetas the Fastest - They can run 80 km...
    (post title) - (a few words from top of post content)

    how can i do it?

  2. turko
    Member
    Posted 6 years ago #

    i also searched codex, but found nothing

  3. tsguitar
    Member
    Posted 6 years ago #

    You could go the plugin route. Pick one from this list:
    http://www.google.com/search?q=recent+posts+wordpress&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

    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):
    http://wordpress.org/support/topic/40378?replies=13

    From the Codex:
    http://codex.wordpress.org/Template_Tags/the_content
    http://codex.wordpress.org/Customizing_the_Read_More

    There are also plugins that allow this same feature without needing to insert any quicktags:
    http://wordpress.org/extend/plugins/tags/more (check the versions they work on)
    http://labitacora.net/comunBlog/limit-post.phps (not sure if it works with WP 2.5.1)

    This looks interesting:
    http://www.jenst.se/2007/08/21/wordpress-create-own-more-tag

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

  4. turko
    Member
    Posted 6 years ago #

    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='";
            the_permalink();
            echo "'>"."..."."</a>";
            echo "";
            echo "<a href='";
            the_permalink();
            echo "'>".$more_link_text."</a>
    ";
       }
       else {
          echo $content;
       }
    }
    
    ?>

    my sidebar:

  5. <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.
  • tsguitar
    Member
    Posted 6 years ago #

    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:
    http://codex.wordpress.org/Template_Tags/wp_get_archives
    http://codex.wordpress.org/Template_Tags/get_archives

    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.

  • tsguitar
    Member
    Posted 6 years ago #

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

    <ul>
    <?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; ?>
    </ul>

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

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags