WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sidebar showing full posts (6 posts)

  1. benedictec
    Member
    Posted 1 year ago #

    Hi everyone!

    I am totally new here and beginningfrom scratch coding!
    I am currently working on this website and especially the right sidebar on the home page.
    As you can see, it shows News and Articles and under each of these, the name of the posts and its dates. What I want to add is a third division called Broadsight Magazine, which I achieved to do but it shows the full posts!

    How could I just get the name and the date?

    I used the following code:
    <h3 class="blog-header">magazine"><?php _e("<!--:en-->Broadsight Magazine<!--:--><!--:th-->แมกกาซีน<!--:-->"); ?></h3>
    <div>
    <?php $magazine = array( 'post_type' => 'magazine', 'posts_per_page' => '3', 'order' => 'DESC', 'orderby'=> 'ID' ); $loop = new WP_Query( $magazine ); while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <h4>"><?php the_title(); ?></h4>
    <?php the_content( __( 'Read the Rest →', 'broadgate' ) ); ?>
    <?php endwhile; ?>
    </div>

    Many thanks for your help!
    Bénédicte

  2. souravb
    Member
    Posted 1 year ago #

    Hi benedictec,

    For getting name use the_title(); and for getting date use the_date();. So you can use:

    <h4><?php the_title(); ?></h4>
    <p><?php the_date(); ?></p>
    <?php get_the_ID(); ?>
    <a href="<?php $post_id=get_the_ID(); echo get_permalink($post_id); ?>"> Read the rest </p>

    instead of`
    <h4>"><?php the_title(); ?></h4>
    <?php the_content( __( 'Read the Rest →', 'broadgate' ) ); ?>`

  3. paulwpxp
    Font hero
    Posted 1 year ago #

    From the source code of your previous 2 sidebar sections, which you are trying to replicate, it *seems that this is kind of a hack. It requires putting a read more quicktag at the topmost of each post content.

    The right way is to not use the_content() as per @souravb, but since it's in the loop, the_permalink() should work.

    So this part

    <?php the_content( __( 'Read the Rest →', 'broadgate' ) ); ?>

    should be

    <p><a href="<?php the_permalink(); ?>"><?php _e( 'Read the Rest →', 'broadgate' ); ?></a></p>

    This won't require you to put in more quicktag at the topmost of each post, which is a wrong way of using more tag.

    Also, don't forget wp_reset_postdata()
    http://codex.wordpress.org/Class_Reference/WP_Query

  4. benedictec
    Member
    Posted 1 year ago #

    Thank you very much for your answers both of you!

    You are right! I need to add a quicktag on each post if I keep the same code!

    Many thanks!!! I least it doesn't look messy now!

  5. souravb
    Member
    Posted 1 year ago #

    Sorry. This is the correct code.

    <h4><?php the_title(); ?></h4>
    <p><?php the_date(); ?></p>
    <a href="<?php $post_id=get_the_ID(); echo get_permalink($post_id); ?>"> Read the rest</a>
  6. benedictec
    Member
    Posted 1 year ago #

    Ok ok! Thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic