Titles Only in Custom Template, with Intro Text

Community Forums Forums Design Tips and Tricks Titles Only in Custom Template, with Intro Text

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  Robin 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #72977

    Mark
    Member
    Post count: 4

    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.

    #73469

    Robin
    Participant
    Post count: 318

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

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.