excerpts on a page template
-
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.
-
start by reading: http://codex.wordpress.org/Pages#Page_Templates
details will depend on your currently used theme.
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?http://codex.wordpress.org/Pages#A_Page_of_Posts is a basic example of how to show posts of some categories;
then there is general information:
http://codex.wordpress.org/The_Loop
http://codex.wordpress.org/Function_Reference/the_excerpt
http://codex.wordpress.org/Function_Reference/the_permalinkwhat theme are you using?
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.
See above – this is my last stab at code for it
<?php $query = new WP_Query( array( 'post_excerpt' => 'post_type'=> 'Movies', ) ); ?>See 2 posts above…
I have managed to do it by using a shorcode plugin but wanted to code it and do without the pluginshort code:
[display-posts post_type="movies" taxonomy="actors" tax_term="red" image_size="thumbnail" include_excerpt="true"]http://codex.wordpress.org/Class_Reference/WP_Query
http://codex.wordpress.org/The_Looptry 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(); ?>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.)
http://codex.wordpress.org/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)
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') ) );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(); ?>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(); ?>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 🙂
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(); ?>
The topic ‘excerpts on a page template’ is closed to new replies.