Community Forums › Forums › Archived Forums › Design Tips and Tricks › Titles Only in Custom Template, with Intro Text
Tagged: template, title only
- This topic has 1 reply, 2 voices, and was last updated 10 years, 5 months ago by Robin.
-
AuthorPosts
-
November 14, 2013 at 12:10 pm #72977MarkMember
I'm looking to create a custom template to list only the titles, as links, for posts in particular categories. I'd also like to display some introductory text above the listing of titles.
After googling this for a while, it seems like I could do this with a custom page template that has a hook in it to remove everything but the title before content is posted. But if I do that, how do insert the introductory text? And how do I get the basic blog-like functionality so that all the titles can be browsed?
I tried something like this:
<?php /*
Template Name: Q and A
*/ ?><?php
add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' );/**
* Show Linked Titles Only for Posts in Category Pages
*
* @author Sridhar Katakam
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/function sk_show_titles_only_category_pages( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
// $query->set( 'posts_per_page', '2' );//* Remove the post info
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );//* Remove the post thumbnail
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );//* Remove the post body
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );//* Remove the post meta
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
}}
?><?php genesis(); ?>
which I found on the web, but it didn't work. Nothing was displayed.
November 16, 2013 at 4:50 pm #73469RobinMemberKind of...you want to just do an action to remove the standard loop and create your own.
`remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop add_action( 'genesis_loop', 'genesis_standard_loop', 5 ); // Include the editor content add_action( 'genesis_loop', 'rgc_do_loop' ); // Add custom loop function rgc_do_loop() { Put your args here for your loop Then preface this with your if/while posts lines echo '<a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">'; echo '</a>'; the_content_limit ( 300, '[ Read More ]' ); // change the number to how long you want the content to be }`
If the titles link to the posts, you may need to use the hooks to remove meta and other information that shouldn't be on it. If you need help setting up the template like this, I've blogged about it. It may not be the best way to do this kind of thing but it's been working for me.
Hope that helps get you started--
I do the best I can with what I’ve got. (say hey on twitter)
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.