Support » Themes and Templates » Sidebar showing full posts

  • Resolved benedictec


    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>
    <?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; ?>

    Many thanks for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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’ ) ); ?>`



    Font hero

    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()

    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!

    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>

    Ok ok! Thanks a lot!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sidebar showing full posts’ is closed to new replies.