• Resolved Mark Shirley

    (@ravalde)


    Hi does anyone know any code to display just post excerpts and links on a page. I’ve managed to do it with shortcode but would like to do it with straight code in my template.

Viewing 15 replies - 1 through 15 (of 16 total)
  • start by reading: https://codex.www.ads-software.com/Pages#Page_Templates

    details will depend on your currently used theme.

    Thread Starter Mark Shirley

    (@ravalde)

    Thanks alchymyth

    I’ve read that article and tons of others but no mention on how to display just a page excerpts

    how to display just a page excerpts

    you need to be a bit more precise with the requirements;

    – how many posts?
    – the latest posts?
    – posts of a certain category?

    https://codex.www.ads-software.com/Pages#A_Page_of_Posts is a basic example of how to show posts of some categories;

    then there is general information:
    https://codex.www.ads-software.com/The_Loop
    https://codex.www.ads-software.com/Function_Reference/the_excerpt
    https://codex.www.ads-software.com/Function_Reference/the_permalink

    what theme are you using?

    Thread Starter Mark Shirley

    (@ravalde)

    Hi thanks for the reply …ok

    I have a number of custom post types called Movies inside those CPT’s I have created excerpts. I have then created a page with a template to display the excerpts.

    Thread Starter Mark Shirley

    (@ravalde)

    See above – this is my last stab at code for it

    <?php
    $query = new WP_Query( array( 'post_excerpt' => 'post_type'=> 'Movies', ) );
    ?>
    Thread Starter Mark Shirley

    (@ravalde)

    See 2 posts above…
    I have managed to do it by using a shorcode plugin but wanted to code it and do without the plugin

    short code:

    [display-posts post_type="movies" taxonomy="actors" tax_term="red" image_size="thumbnail" include_excerpt="true"]

    https://codex.www.ads-software.com/Class_Reference/WP_Query
    https://codex.www.ads-software.com/The_Loop

    try this fundamental query and loop:

    <?php
    $query = new WP_Query( array( 'post_type'=> 'Movies' ) );
    if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
    the_excerpt();
    endwhile; endif;
    wp_reset_postdata();
    ?>

    Thread Starter Mark Shirley

    (@ravalde)

    Brilliant – thanks – wow – i’ve been trying to do this for days. Question if I wanted to show just the excerpts from say a taxonomy of actor and taxonomy terms peter smith and mary brown what would the code be.

    Thanks your a star alchymyth ??

    it might work this way:

    $query = new WP_Query( array( 'post_type'=> 'Movies', 'actors' => array('peter-smith','mary-brown') ) );

    (untested)(using the taxonomy ‘actors’ and the assumed slugs of the taxonomy terms ‘peter smith’ etc.)

    https://codex.www.ads-software.com/Class_Reference/WP_Query#Taxonomy_Parameters – ‘simple taxonomy query’

    or:

    $query = new WP_Query( array( 'post_type'=> 'Movies', 'tax_query' => array( 		array(
    			'taxonomy' => 'actors',
    			'field' => 'slug',
    			'terms' => array('peter-smith','mary-brown')		)
    ) );

    (untested as I don’t have test data available)

    Thread Starter Mark Shirley

    (@ravalde)

    I tried this below but my browser just went blank – we are nearly there

    <?php
    $query = new WP_Query( array( 'post_type'=> 'Movies', 'Actors' => array('peter-smith','mary-brown') );
    if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
    the_excerpt();
    endwhile; endif;
    wp_reset_postdata();
    ?>

    my mistake –
    this line is missing a closing bracket – corrected below:

    $query = new WP_Query( array( 'post_type'=> 'Movies', 'Actors' => array('peter-smith','mary-brown') ) );
    Thread Starter Mark Shirley

    (@ravalde)

    Umhh thanks – I get all 3 post excerpts displaying despite the fact I put in a different taxonomy term in the 3rd CPT.

    code used:

    <?php
    $query = new WP_Query( array( 'post_type'=> 'Movies', 'Actors' => array('peter-smith','mary-brown') ) );
    if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
    the_excerpt();
    endwhile; endif;
    wp_reset_postdata();
    ?>

    Thread Starter Mark Shirley

    (@ravalde)

    I’ve managed to get it working just targeting a taxonomy term

    <?php
    $query = new WP_Query( array( 'actors' => 'peter-smith' ) );
    if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
    the_excerpt();
    endwhile; endif;
    wp_reset_postdata();
    ?>
    Thread Starter Mark Shirley

    (@ravalde)

    Now if I could add the post type that would give me a lot of flexibility but happy with what I’ve got at the moment ??

    Thread Starter Mark Shirley

    (@ravalde)

    This works a treat

    <?php
    $query = new WP_Query( array( 'actors' => 'peter-smith', 'actress' => 'jane-smith' ) );
    if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post();
    the_excerpt();
    endwhile; endif;
    wp_reset_postdata();
    ?>
Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘excerpts on a page template’ is closed to new replies.