WordPress.org

Ready to get started?Download WordPress

Forums

Question about post summaries on front page (6 posts)

  1. knightmetal
    Member
    Posted 11 months ago #

    Hello,

    I use the <!--more--> tag to split my text so that only the first paragraph (or a part of it) is shown on my front page. I came across an issue, say I have the following,

    1. Introduction
    2. Content
    3. Conclusion

    1. Introduction
    A few lines for the introduction...
    A few lines for the introduction...
    A few lines for the introduction...

    The question is, how can I strip off the table of content so that in my front page I only show the "few lines for the introduction"? Is there any tag to remove the top part of my article? something like

    <!--a tag in here?-->
    A few lines for the introduction...
    A few lines for the introduction...
    A few lines for the introduction...
    <!--more-->

    Thanks for your help.

  2. nullvariable
    Member
    Posted 11 months ago #

    There are no built-in functions for this. You could use a custom shortcode and wrap content you want hidden from excerpts like:

    [Fullpostonly]some text here[/fullpostonly]

    http://codex.wordpress.org/Shortcode_API should help get you started in that direction.

  3. knightmetal
    Member
    Posted 11 months ago #

    Thanks nullvariable,

    I'm not experienced in creating shortcodes but if that's the only solution, then I'll give it a try :)

  4. knightmetal
    Member
    Posted 11 months ago #

    Hi again,

    I went through the Codex on Shortcodes and found an example similar to what I needed, by changing a few things I made it work but I came across a different issue. If I'm on the front page it shows the paragraph that I want, so far so good. Now the question is, how do I make it reappear when the user wants to read the whole post? Here's the function I'm using, very simple but it works.

    // Hide text
    function hide_text_shortcode( $atts, $content = null ) {
    return '<div style="display:none">' . $content . '</div>';
    }
    add_shortcode( 'hide_text', 'hide_text_shortcode' );

  5. nullvariable
    Member
    Posted 11 months ago #

    another thing I didn't think of was that you could just use the excerpt field instead of the <!--more--> tag. That will allow you to custom craft (or copy paste) the excerpt text so that it does not contain your ToC and display as you described.

    If you wanted to still go the shortcode route, you'd need to make the shortcode conditional.

    // Hide text
    function hide_text_shortcode( $atts, $content = null ) {
      global $post;
      if (is_single($post) {
        return $content;
      } else {
        return;
      }
    }
    add_shortcode( 'hide_text', 'hide_text_shortcode' );

    that asks wordpress if the page/post is the only one being shown, if it is, then it displays the text inside the shortcode, if it's not single (archive pages, list pages, tag pages, etc) then it returns nothing, which *should* mean that the ToC is only visible on the single post/page views of the site.

  6. knightmetal
    Member
    Posted 11 months ago #

    Thanks man, it works :)

Reply

You must log in to post.

About this Topic