• Resolved zombysis

    (@zombysis)


    Hi!
    I built a theme from scratch and this is the first time coding a theme on my own so I don’t know so much concerning building a theme in WordPress yet so please forgive me if this is a stupid question! 😉

    What I wanna do is: I have div elements on my front page that are styled as boxes in which the excerpt of a post is displayed.
    My question now is how can I display the excerpt in a box that has a certain class (“small-box”) and the content if the box has another class (“big-box”)?

    I would be more than happy if you could help me with that question!

    If you have got even more time to help me, maybe you could also help me with that:
    I want the boxes on the front page to get bigger on click “read more” and in that big box I want to display the content whereas in the small box I want to display the excerpt.
    What I thought I could do is toggle the class on click “read more” and though a conditional statement would display the excerpt in the div/box if this box has the class “small-box” etc.
    Maybe there is a much better way to do that though and I haven’t quite succeded yet to get where I wanted…
    Here is the theme I’m working on if you want to see what I mean: http://themes.inflamedpassion.com/

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Casey Driscoll

    (@caseypatrickdriscoll)

    Hi zombysis!

    Congrats on making your first theme!

    If I understand your first question correctly, it should be simple enough.

    In the loop, I would simply output the excerpt and the content and then control the display with css.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    $boxsize = ( logic ) ? for : boxsize; // big-box || small-box
    ?>
    
    <div class="box <?php echo $boxsize; ?>">
      <div class="excerpt"><?php the_excerpt(); ?></div>
      <div class="content"><?php the_content(); ?></div>
    </div>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    Then with css just simply add a rule to show/hide the excerpt/content depending on the size of the box:

    .box .excerpt, .box .content { display: none; }
    .big-box .content { display: block; }
    .small-box .excerpt { display: block; }

    Your logic on the box size of course depends on whatever it is you are trying to make.

    http://codex.wordpress.org/Function_Reference/the_excerpt
    http://codex.wordpress.org/Function_Reference/the_content

    Does this make sense? Let me know if this isn’t what you are looking for.

    Cheers!

    Casey

    Thread Starter zombysis

    (@zombysis)

    Awesome, thanks, works perfectly well!!

    Just one more question if you’ve got the time: I would like to add another class to the post thumbnail using jQuery. In order to do that I need to give the image an id but I don’t know how?
    I want the id to be “image-<?php the_ID(); ?>” and the class added should be “img-thumb”.
    Is there a function that can do that? I tried wrapping the image into a div and then adding a new class to the div but that didn’t work…

    Thread Starter zombysis

    (@zombysis)

    Oh yeah and another one (Sorry to bother you that much!): I want a background for the whole website but for some reason putting it in body { ...} doesn’t work… Neither do font and text-align so I don’t know what`s up with the body thing?

    Thread Starter zombysis

    (@zombysis)

    Nevermind, I’ve already got it! Actually it was so easy and obvious -.- didn’t even need an image id or jQuery… oh well…
    But thank you very much for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP/jQuery – show content if div has one class, excerpt if it has another class?’ is closed to new replies.