• Resolved wildbug

    (@wildbug)


    Is it possible to convert this code:

    <?php
    	$wp_query = $tmp_query;
    	if (have_posts()) : $count = 0;
    	?>
    	<ul>
    	<?php while (have_posts()) : the_post(); $count++; ?>
    	<li<?php if ($count==1) echo ' class="first"'; ?>>
    		<div class="survivetitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    		<a class="attachment" href="<?php the_permalink(); ?>"><?php fs_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
    		<p><?php echo fs_clean($post->post_excerpt, 300); ?>...</p>
    	</li>
    	<?php endwhile; ?>
    	</ul>
    	<?php else: ?>
    	<p><?php fs_lang("No articles."); ?></p>
    	<?php endif; ?>

    so that it will automatically convert the div on the permalink/title to become the parent category of the post?

    All posts on my site will either fall under the “thrive” or “survive” parent categories. I want to style the title’s of posts differently based on the parent category. I saw this suggested somewhere but it doesn’t use the parent category, it uses the category slug. I need to use the parent category slug. Not to mention, it produces an error message on my site. Help!:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>????<div class="?<?php?foreach((get_the_category()) as $cat)?{?echo $cat->category_nicename; ?}??>">?
    ?<h1><?php the_title(); ?></h1>?<?php the_content(); ?>?</div>?<?php endwhile; else: ?>?<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>?<?php endif; ?>

    Seems so simple to do if you’re a programmer (which I”m not…) but I could not find a solution in the forums. Thanks in advance for your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • check for each post category if the category has a parent category, then echo the parent category slug;
    example:

    <div class="<?php foreach((get_the_category()) as $cat) { if($cat->category_parent) echo get_category($cat->category_parent)->slug . ' '; } ?>">

    Thread Starter wildbug

    (@wildbug)

    That would be great if it worked. It’s not showing any styling though.
    Here is what I have in my index template now:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Is the space after “thrive” and “survive” the problem? If so, how to fix it? If not, have any ideas on why it’s not working? Many thanks!

    unless you added new css for styling, the styling might be based on the prior css class .survivetitle

    space after a css class is no problem.

    for suggestions about css/formatting, please post a link to your site.

    Thread Starter wildbug

    (@wildbug)

    It definitely is based on the styling I had in place before; I just removed the “title” from the class. But the styling I had before is no longer displaying once I added your suggested code….here is my test site.

    .thrive and .survive seem to have the same styling – purple and a heart as background.

    try to clear the browser cache to make the latest css changes visible – ‘reload’ or press ‘CTRL F5’

    Thread Starter wildbug

    (@wildbug)

    My bad!! Dang, I thought I had styled them differently. Sorry for causing you extra effort. You ROCK! Thank you so much for helping me, I really really appreciate it!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to create sexy parent category styling’ is closed to new replies.