Set post classes to wordpress

I have a small problem!

I'm trying to add this code to my loop

<?php post_class (); ?>

in to this code:

    <?php $ccfit_loop = new WP_Query( array( 'post_type' => 'photo', 'posts_per_page' => 9999 ) ); ?>

        <?php if ( $ccfit_loop->have_posts() ) : ?>
            <?php while ( $ccfit_loop->have_posts() ) : $ccfit_loop->the_post(); ?>
                <?php
   $ccfit_img_big = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_id() ), 'ccfit_big', false ); 
            echo '<div id="blogpost" HERE SOULD THE CODE BE><a href="'. get_permalink( $id ) .'"><h2>'. get_the_title() .'</h2></a><img src="'. $ccfit_img_big[0] .'"></div>';
                ?> 
            <?php endwhile; ?>
        <?php endif; ?>

Grateful for the quick reply!

Solutions

Replace following code:

<?php
    $ccfit_img_big = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_id() ), 'ccfit_big', false ); 
    echo '<div id="blogpost" HERE SOULD THE CODE BE><a href="'. get_permalink( $id ) .'"><h2>'. get_the_title() .'</h2></a><img src="'. $ccfit_img_big[0] .'"></div>';
?>

WIth this:

<?php
    $ccfit_img_big = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_id()), 'ccfit_big', false );
?>
<div id="blogpost" <?php post_class(); ?>>
    <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
    <img src="<?php echo $ccfit_img_big[0]; ?>">
</div>
Tags: PHP / Wordpress

Similar questions

Yoast Seo Plugin - Set no-index to a post automatically when a post is set to sticky
I am a content supervisor on a wordpress site, it uses wordpress seo by yoast plugin. My duty includes analyzing the content and marking it sticky if seems fit. When I mark a particular post as sticky, there is a function which then sets the post to only appear on the category page. Next thing I have to do is manually set the single-post-view to no...
What is wordpress way to access a plugin's classes/models to load custom post type data?
New to Wordpress development. I am using a plugin that uses custom posts types to create online courses. I noticed that the plugin has a file called /wp-content/plugins/sfwd-lms/includes/classes/class-ldlms-topic-model.php It contains: So in a hook action I am trying to access the plugin's models. For instance as so: But I get this error: I just ca...
How can I post the posts with different classes in Wordpress loop?
I have such layout in my HTML file. HTML How can I use WP loop to repeat the same sequence? I need that whenever the user wants to publish the posts, and the user has the option(choice) to publish the 3 posts with different classes in one row with class="section". Please, experts in WP help!
Add multiple classes name to post thumbnail in Wordpress
this is a wordpress problem. I know I can add a class to a wordpress featured image via this: However how do I add multiple? I tried using an array but it just displays array in inspecter and I am not sure if it worked. Please help. Thanks.
Assign multiple categories as classes from custom post types in wordpress
I have set up some custom post types and I am trying to achieve an on-page filter using javascript. I have managed to be able to output the first class that is signed, but I cannot get it to add multiple classes. Ideally, I don't want to have to hardcode the categories as I will be handing this over to a client and they will be adding many more in ...
Apply Classes to post text inside editor
I am using a theme that comes with several different font stylings for headers and text. However there is no simple way to apply these classes inside the editor. How can I enable a drop down similar to TinyMCE that allows me to select text and apply a class/style to it in order to have my marketing and sales department style their posts.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.