Dominic
Dominic

Reputation: 341

How do I use get_content WordPress function?

I am not able to fetch content while using the the_content WordPress function.

 <!-- Start the Loop. -->
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( in_category( '3' ) ) : ?>
        <div class="post-cat-three">
    <?php else : ?>
        <div class="post">
    <?php endif; ?>
    <!-- Display the Title as a link to the Post's permalink. -->
    <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
    <small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
    <!-- Display the Post's content in a div box. -->
    <div class="entry">
        <?php the_content(); ?>
    </div>
    <!-- Display a comma separated list of the Post's Categories. -->
    <p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>
    </div> <!-- closes the first div box -->
    <!-- Stop The Loop (but note the "else:" - see next line). -->
 <?php endwhile; else : ?>
    <!-- The very first "if" tested to see if there were any Posts to -->
    <!-- display.  This "else" part tells what do if there weren't any. -->
    <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <!-- REALLY stop The Loop. -->
 <?php endif; ?>

I have really tried but get empty description result kindly help

Upvotes: 0

Views: 199

Answers (1)

user8331407
user8331407

Reputation:

Here a example fetch description from post in Wordpress

 <?php 
$categories = get_the_category( $id );
if( $categories ){
  // Assumes you just want the first category
  print 'You&#8217;re in the ' . $categories[ 0 ]->name . ' category';
}
?>
<ul>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
 
        $attachments = get_posts( array(
            'post_type'   => 'attachment',
            'numberposts' => -1,
            'post_status' => null
        ) );
         
        if ( $attachments ) {
            foreach ( $attachments as $attachment ) {
                ?>
                <li><?php echo wp_get_attachment_image( $attachment->ID, 'full' ); ?>
                    <p><?php echo apply_filters( 'the_title', $attachment->post_title ); ?></p>
                    
                </li>
                <?php
            }
        }
    endwhile; endif; ?>
</ul>
  <p><?php echo apply_filters( 'the_title', $attachment->post_title ); ?></p> <!-- do you need change post_title for description --> 

Upvotes: 1

Related Questions