WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show post category in single post mode + add class to current post-title (16 posts)

  1. EntarteteMuzak
    Member
    Posted 3 years ago #

    Hi,

    I'm coding a website for a friend who got the layout from an agency that clearly has no concept on how to do webdesign. Now I'm stuck with their layout. Anyway, I need to make the following happen:

    In single post mode, I want to list all the posts (with title, excerpt and read more link)from the same category. This could be achieved with a related category widget plugin. The only problem is that I need the current post to be in the category list and I need to add a class to the title in order to display the post as "active".

    Anyone?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    actually quite simple:

    http://pastebin.com/jusftGJR

  3. EntarteteMuzak
    Member
    Posted 3 years ago #

    Hey, thanks!

    How do I add this bit of code to yours?

    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    <?php if ($count%3== 0) : ?>
    
    // third post content
    
    <?php else : ?>
    
    // regular content
    
    <?php endif; ?>
    <?php endwhile; ?>
    <?php endif; ?>

    I need it in order to add a hr after the first 3 posts.

  4. EntarteteMuzak
    Member
    Posted 3 years ago #

    Fixed it!

    http://pastebin.com/RDVtVG8Z

    [code moderated as per forum rules - if it is different from the above pastebin, please use a further pastebin]

  5. EntarteteMuzak
    Member
    Posted 3 years ago #

    Aw, snap!
    If I use the_excerpt for the category list posts and then click on a single post, the_excerpt in the list post disappears, and only the_content of the single post is visible.

    Suggestions?

  6. EntarteteMuzak
    Member
    Posted 3 years ago #

    Perhaps I could use this?

    <?php echo get_the_excerpt( $post->parent ); ?>

    I tried:
    <?php if($post->ID == $this_post_id) echo get_the_excerpt( $post->parent ); ?>
    with no luck

  7. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    If I use the_excerpt for the category list posts and then click on a single post, the_excerpt in the list post disappears, and only the_content of the single post is visible.

    as i understood, this category list posts is used in single.php anyway (?)

    so, i would think, if you click on a single post, you simply get a new single post with the same or a different list.

    can you post a link to your site to illustrate what you describe?

  8. EntarteteMuzak
    Member
    Posted 3 years ago #

    Ah, I saw that <?php echo get_the_excerpt( $post->post ); ?> should be <?php echo get_the_excerpt( $post->post_parent ); ?>.

    Anyway, no sorry I haven't got the site online yet.

    To illustrate:

    POST1, POST2, POST3,
    POST4, POST5, POST6
    
    Single POST1

    If I click on the permalink for POST1 the excerpt for that post disappears.
    I want the excerpt to stay, even if the content of the post is shown below.

  9. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    imho, $post->post_parent only works for hierarchical post types such as pages.

    http://codex.wordpress.org/Function_Reference/get_the_excerpt
    does not have any parameter.

    to get the code in the full context, can you paste the whole template into a http://pastebin.com/ and post the link to it here?

  10. EntarteteMuzak
    Member
    Posted 3 years ago #

    Oh, of course that doesn't work then....

    http://pastebin.com/NTwYAYSh

  11. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    If I click on the permalink for POST1 the excerpt for that post disappears.

    i can't reproduce this - in my test setup, the excerpt of the 'active' post in the list stays.

    maybe something to do with your css?

  12. EntarteteMuzak
    Member
    Posted 3 years ago #

    Found the problem!
    The WP Columnize plugin causes the excerpt to go away. Wonder why?
    If I disable that plugin even the <?php if($post->ID == $this_post_id) echo get_the_excerpt( $post->post_parent ); ?> works.

  13. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    well done -

    even the <?php if($post->ID == $this_post_id) echo get_the_excerpt( $post->post_parent ); ?> works

    yes - get_the_excerpt() would simply ignore anything in the brackets.

    if this is all working now, please mark this thread as 'resolved' - thanks

  14. EntarteteMuzak
    Member
    Posted 3 years ago #

    Well yes and no, but I guess it is working sort of.
    It seems that if I use the auto excerpt while using the Columnizer shortcode the excerpt disappears. But if I manually write the excerpt everything works.

  15. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    well - look into the code of the 'columnizer' plugin to see if and how (and why) it messes with the excerpt ...

  16. EntarteteMuzak
    Member
    Posted 3 years ago #

    Yes, I think I'll have to look into that.
    Thanks for all help

Topic Closed

This topic has been closed to new replies.

About this Topic