Combining 2 sections of JS code
-
Hello folks, I’d like to combine two bits of JS code but I don’t have the JS savvy to do it. Can someone please help. The first piece of code is to set up a category of Popular Posts [=stickies]. It runs like this.
function wpb_latest_sticky() { /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Get the 5 newest stickies (change 5 for a different number) */ $sticky = array_slice( $sticky, 0, 5 ); /* Query sticky posts */ $the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) ); // The Loop if ( $the_query->have_posts() ) { $return .= '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); $return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>'; } $return .= '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata(); return $return; } add_shortcode('latest_stickies', 'wpb_latest_sticky'); add_filter('widget_text', 'do_shortcode');
The second piece of code is supposed to get blogs in alphabetical order (tho for me, it’s not working yet). It goes like this:
function change_posts_order( $query ) { if ( $query-is_home() && $query-is_main_query() ) { $query-set( 'orderby', 'title' ); $query-set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', ' change_posts_order ' );
Is anyone able to help me with a piece of code that will get my stickies displaying in alphabetical order, please?
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Combining 2 sections of JS code’ is closed to new replies.