1

I need to create a custom loop for a custom post type archive template, that is as similar to this page as possible (www.manta.com/totd) using the Genesis framework.

Here is a paste of what I have, which is not working.

http://pastebin.com/g1EK5f6M

As well as the current archive template http://pastebin.com/A6UufNMu which produces this: m.angiemeekerdesigns.com/totd

Can someone help me learn why my current code isn't working?

Update: After working on it some, I've come to the paste below - it's working about 80% of what I need, except that the one post from the first loop at the top (feature) is showing the content that the posts from the second loop below should be showing, and vice versa.

Here's a link to page on the site now: http://m.angiemeekerdesigns.com/totd

and the code as far as I've gotten.

<?php

/**
 *
 * Display the Tip of the Day Custom Post Type archive custom fields using
 * ACF.
 *
 * @author Angie Meeker
 * @uses   Advanced Custom Fields
 */

 add_action('genesis_entry_content','genesis_do_post_title', 2);

 //* Removes Continue Reading from the echoed excerpt
 function sbt_auto_excerpt_more( $more ) {
return 'aaa';
}
add_filter( 'excerpt_more', 'sbt_auto_excerpt_more', 20 );

function sbt_custom_excerpt_more( $output ) {return preg_replace('/<a[^>]+>Continue reading.*?<\/a>/i','',$output);
}
add_filter( 'get_the_excerpt', 'sbt_custom_excerpt_more', 20 );


 //* Add Tip of the Day body class to the head
add_filter( 'body_class', 'add_tiparchives_body_class' );
function add_tiparchives_body_class( $classes ) {
   $classes[] = 'tiparchives-post-type-archive-{tipoftheday}';
   return $classes;
}

 // Return Category and Tip of the Day on Single Posts
add_action ( 'genesis_before_content', 'show_totd', 9 );
function show_totd() {
    echo '<div class="totd-cats-title">Tip of the Day</div>';
} 
  // Remove Post Author
 add_filter( 'genesis_post_info', 'remove_post_author_totd_posts' );
function remove_post_author_totd_posts($post_info) {
    $post_info = '[post_date]';
    return $post_info;
}


/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'manta_tips_feature' );
add_action( 'genesis_loop', 'manta_tips_teasers' );





/** Show the first first post from the TOTD Custom Post Type */

function manta_tips_feature() {


 echo '<div class="entry-highlight">Current Tip of the Day</div>';
    global $paged; // current paginated page
    global $query_args; // grab the current wp_query() args
    $args = array(
        'post_type' => 'tipoftheday',
        'posts_per_page'=> '1',
        'paged'  => $paged,
    );

    genesis_custom_loop( wp_parse_args($query_args, $args) );
 // Return if CPT Tip of the Day
add_action( 'genesis_after_entry_content', 'manta_tips_pre_features' );
function manta_tips_pre_features() {

        // Store the pre tips data
        $tips_data_pre = array(
                'totd_tags' => get_field( 'totd_tags' ),
                'tip_article_headline' => get_field( 'tip_article_headline' ),
                'article_author' => get_field( 'article_author' ),
                'article_author_link' => get_field( 'article_author_link' ),
        );


// Only output if we have tips data    
        if ($tips_data_pre['totd_tags'] != '' ||
                $tips_data_pre['tip_article_headline'] != '' ||
                $tips_data_pre['article_author'] != '' ||
                $tips_data_pre['article_author_link'] != '') {

                echo '<div class="tip-excerpt"><p><div class="entry-content">';

                                echo '<div class="entry-terms">' , do_shortcode('[post_terms taxonomy="totd_tags" before="See More Tips For: " taxonomy="totd_tags"] '),'</div>' ;
                                echo '<div class="entry-terms">
                                                                                <div class="share">Share This Tip:</div>
                                                                                        <div class="addthis_toolbox addthis_default_style">
                                                                                                <a class="addthis_button_preferred_1"></a>
                                                                                                <a class="addthis_button_preferred_2"></a>
                                                                                                <a class="addthis_button_preferred_3"></a>
                                                                                                <a class="addthis_button_preferred_4"></a>
                                                                                                <a class="addthis_button_compact"></a>
                                                                                                <a class="addthis_counter addthis_bubble_style"></a>
                                                                                        </div>
                                                                                        <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=manta"></script>
                                                                                </div>
                                                                </div></div>';


                echo '</p><div class="divider"></div>';
        }
}
}

/** Show the first 10 previous posts from the TOTD Custom Post Type */

function manta_tips_teasers() {


 echo '<div class="entry-highlight">Previous Tips</div>';
    global $paged; // current paginated page
    global $query_args; // grab the current wp_query() args
    $args = array(
        'post_type' => 'tipoftheday',
        'posts_per_page'=> '10',
        'paged'  => $paged,
    );

    genesis_custom_loop( wp_parse_args($query_args, $args) );


 // Return if CPT Tip of the Day
add_action( 'genesis_after_entry_content', 'manta_tips_teaser_pre' );
function manta_tips_teaser_pre() {

        // Store the pre tips data
        $tips_data_pre = array(
                'totd_tags' => get_field( 'totd_tags' ),
        );


// Only output if we have tips data    
        if ($tips_data_pre['totd_tags'] !='') {

                echo '<div class="tip-excerpt"><p><div class="entry-content">';

                                echo '<div class="entry-terms">' , do_shortcode('[post_terms taxonomy="totd_tags" before="See More Tips For: " taxonomy="totd_tags"] '),'</div>' ;

                echo '</p><div class="divider"></div>';
        }
}
}


genesis();
  • Exactly what isn't working? – s_ha_dum Feb 3 '14 at 23:14
  • I'm not sure - the function_manta_tips_pre () and function manta_tips_teaser_pre() are correct. I think it's the querys wrapping those functions that is incorrect, but I'm not sure why or where. – angiemeeker Feb 4 '14 at 2:57
  • I have gotten it about 80% of where I need to go! :-) pastebin.com/Wx1f4wmL produces this m.angiemeekerdesigns.com/totd but for some reason, that's actually backwards. The current post (feature) should have the tags/social, the previous (teasers) shouldn't. – angiemeeker Feb 4 '14 at 3:54
  • Please post relevant code here. If (when) that pastebin expires the question becomes unintelligible. – s_ha_dum Feb 4 '14 at 4:41
  • Thanks @s_ha_dum - I added the latest paste to the original post. Is that the best place for it? – angiemeeker Feb 4 '14 at 5:05
2

This is what worked. You can see the results at m.angiemeekerdesigns.com/totd. I am still working on getting the lower posts to have fewer words in their excerpts, and to have slightly different styling, but I think that's a different question than this one.

/**
 *
 * Display the Tip of the Day Custom Post Type archive custom fields using
 * ACF.
 *
 * @author Angie Meeker
 * @uses   Advanced Custom Fields
 */

add_action('genesis_entry_content','genesis_do_post_title', 2);

//* Removes Continue Reading from the echoed excerpt
add_filter( 'excerpt_more', 'sbt_auto_excerpt_more', 20 );
function sbt_auto_excerpt_more( $more ) {
        return 'aaa';
}


add_filter( 'get_the_excerpt', 'sbt_custom_excerpt_more', 20 );
function sbt_custom_excerpt_more( $output ) {
        return preg_replace('/<a[^>]+>Continue reading.*?<\/a>/i','',$output);
}



 //* Add Tip of the Day body class to the head
add_filter( 'body_class', 'add_tiparchives_body_class' );
function add_tiparchives_body_class( $classes ) {
   $classes[] = 'tiparchives-post-type-archive-{tipoftheday}';
   return $classes;
}

 // Return Category and Tip of the Day on Single Posts
add_action ( 'genesis_before_content', 'show_totd', 9 );
function show_totd() {
                echo '<div class="totd-cats-title">Tip of the Day</div>';
}
  // Remove Post Author
add_filter( 'genesis_post_info', 'remove_post_author_totd_posts' );
function remove_post_author_totd_posts($post_info) {
        $post_info = '[post_date]';
        return $post_info;
}


/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'totd_do_loop');
//add_action( 'genesis_loop', 'totd_teasers_do_loop');

add_action('genesis_loop', 'totd_do_loop');
function totd_do_loop() {
        global $wp_query;
        // Set up your query here
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        $query = array(
                'post_type'      => 'tipoftheday',
                'orderby'        => 'date',
                'posts_per_page' => '11',
                'paged'          => $paged,

        );

        $wp_query = new WP_Query( $query );

        if( $wp_query->have_posts() ):
                while( $wp_query->have_posts() ): $wp_query->the_post();
                        // Get the custom fields
                                // Store the pre tips data
        $tips_data_pre = array(
                'totd_tags' => get_field( 'totd_tags' ),
                'tip_article_headline' => get_field( 'tip_article_headline' ),
                'article_author' => get_field( 'article_author' ),
                'article_author_link' => get_field( 'article_author_link' ),
        );


        // Only output if we have tips data
        if ($tips_data_pre['totd_tags'] != '' ||
                $tips_data_pre['tip_article_headline'] != '' ||
                $tips_data_pre['article_author'] != '' ||
                $tips_data_pre['article_author_link'] != '') {

               echo '<span class="date time published" title="%1$s">' , do_shortcode('[post_date]'),'</span>' ;
                echo '<div class="tip-excerpt"><p><div class="entry-content">';
     echo '<div class=h1 entry-title"><a href="'.get_permalink().'"title="'.get_the_title().'">' . get_the_title() . '</a></div>';
                                            echo the_excerpt();
                                echo '<div class="entry-terms">' , do_shortcode('[post_terms taxonomy="totd_tags" before="See More Tips For: " taxonomy="totd_tags"] '),'</div>' ;
                                if( $wp_query->current_post == 0 && !is_paged() ) {
                                    echo '<div class="entry-terms">';
                                        echo '<div class="share">Share This Tip:</div>';
                                        echo '<div class="addthis_toolbox addthis_default_style">';
                                            echo '<a class="addthis_button_preferred_1"></a>';
                                            echo '<a class="addthis_button_preferred_2"></a>';
                                            echo '<a class="addthis_button_preferred_3"></a>';
                                            echo '<a class="addthis_button_preferred_4"></a>';
                                            echo '<a class="addthis_button_compact"></a>';
                                            echo '<a class="addthis_counter addthis_bubble_style"></a>';
                                        echo '</div>';
                                        echo '<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=manta"></script>';
                                    echo '</div>';
                                }

                echo '</div></p><div class="divider"></div></div>';
        }

                endwhile;
                // Pagination! Woo!
                genesis_posts_nav();
        endif;
        // Reset the query
        wp_reset_query();
        }

genesis();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.