WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Show post category in single post mode add class to current post-title

[Resolved] Show post category in single post mode add class to current post-title

  • 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?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    actually quite simple:

    http://pastebin.com/jusftGJR

    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.

    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]

    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?

    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

    Moderator Michael

    @alchymyth

    Forum Moderator

    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?

    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.

    Moderator Michael

    @alchymyth

    Forum Moderator

    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?

    Oh, of course that doesn’t work then….

    http://pastebin.com/NTwYAYSh

    Moderator Michael

    @alchymyth

    Forum Moderator

    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?

    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.

    Moderator Michael

    @alchymyth

    Forum Moderator

    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

    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.

    Moderator Michael

    @alchymyth

    Forum Moderator

    well – look into the code of the ‘columnizer’ plugin to see if and how (and why) it messes with the excerpt …

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

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Resolved] Show post category in single post mode add class to current post-title’ is closed to new replies.