• Resolved sibichan

    (@sibichan)


    Here is my code for frontpage.php. Iam trying to make the box type home. Screenshot here https://i.imgur.com/DavVING.jpg

    <?php while ( have_posts() ) : the_post(); ?>
    
    <div class="col-md-4">
        <div class="sok-blog-box">	
            <?php if ( has_post_thumbnail() ) { ?>
            <figure class="sok-thumb">
            <?php echo get_the_post_thumbnail(); ?>
            </figure>
            <?php } ?>
    
            <div class="sok-blog-summary">	
                <?php
                the_title(
                sprintf( '<h2 class="blog-entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
                '</a></h2>'
                );
                ?>	
                <?php the_excerpt(); ?>
    
                <?php
                wp_link_pages(
                array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
                'after'  => '</div>',
                )
                );
            ?>
            </div>
        </div><!-- .sok-blog-listing -->
    </div>

    I need to show more text if post doesnot have thumbnail. In screenshot here https://i.imgur.com/DavVING.jpg you can see many empty space in a box that doesn’t have thumbnail.

    Now I limitted the excerpt in functions.php using below code.

    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

    • This topic was modified 3 years, 1 month ago by sibichan.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @sibichan

    function mytheme_custom_excerpt_length( $length ) {
        return 20;
    }
    add_filter( 'excerpt_length', 'mytheme_custom_excerpt_length', 999 );

    update your code like this, this will resolve your issue

    Thanks

    Thread Starter sibichan

    (@sibichan)

    @yogeshyadav20 first check the above frontpage.php. Then read below

    I need to show more text if post doesnot have thumbnail. In screenshot here https://i.imgur.com/DavVING.jpg you can see many empty space in a box that doesn’t have thumbnail.

    swayam.tejwani

    (@swayamtejwani)

    You can modify your code to something like this

    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <div class="col-md-4">
        <div class="sok-blog-box">	
            <?php if ( has_post_thumbnail() ) { ?>
            <figure class="sok-thumb">
            <?php echo get_the_post_thumbnail(); ?>
            </figure>
            <?php } ?>
    
            <div class="sok-blog-summary">	
                <?php
                the_title(
                sprintf( '<h2 class="blog-entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
                '</a></h2>'
                );
                ?>	
                <?php 
                if(has_post_thumbnail()){
                    the_excerpt();    
                }else{
                    $text = get_the_content();
                    $words = 80;
                    $more = ' […]';
                     
                    $excerpt = wp_trim_words( $text, $words, $more );
                    echo $excerpt;
                }
                 ?>
    
                <?php
                wp_link_pages(
                array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
                'after'  => '</div>',
                )
                );
            ?>
            </div>
        </div><!-- .sok-blog-listing -->
    </div>
    
    

    this should work I guess

    Thread Starter sibichan

    (@sibichan)

    Thank you @swayamtejwani

    Thread Starter sibichan

    (@sibichan)

    How to make a link to the post page in post_thumbnail and default image ?

    Here is my code.

    <figure class="sok-thumb">
    <?php if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else { ?>
    <img src="<?php bloginfo('stylesheet_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
    <?php } ?>
    </figure>
    swayam.tejwani

    (@swayamtejwani)

    this

    
    <figure class="sok-thumb">
    <?php if ( has_post_thumbnail() ) {
    echo '<a href="'.get_the_permalink().'">'.get_the_post_thumbnail().'</a>';
    } else { ?>
    <a href="<?php echo get_the_permalink(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" /></a>
    <?php } ?>
    </figure>
    
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘If thumbnail doesn’t exist, show more post content’ is closed to new replies.