Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding PHP query to front-page.php (Education Pro)
Tagged: the_wp_tiles
- This topic has 5 replies, 3 voices, and was last updated 7 years, 10 months ago by hawb2000.
-
AuthorPosts
-
June 20, 2016 at 9:35 pm #187901hawb2000Member
I'm trying to customize a plugin by inserting some PHP into front-page.php as per the instructions of the plugin creator:
// Try to get all the top posts in a single query $first_posts = get_posts( array( 'category' => array( 6, 7, 8 ) ); // Then get all the posts that should end up last $last_posts = get_posts( array( 'category' => 5 ); // Merge the 2 arrays of posts, first posts first, last posts last $posts = array_merge( $first_posts, $last_posts ); // Display the tiles! (WP Tiles 1.0 only!) the_wp_tiles( $posts );
However I'm not too well versed with PHP and I'm not really sure where to place this snippet, and whether I need to place it inside a function. front-page.php has a widget area named Top, which is where I'd like these posts to be displayed:
genesis_widget_area( 'home-top', array( 'before' => '<div class="home-top widget-area"><div class="wrap">', 'after' => '</div></div>', ) );
but I'm not too confident where I should place this snippet. Apologies for the vagueness of the question, I'm a bit out of my depth.
Thanks
June 21, 2016 at 12:47 am #187913WilliamMemberadd_action("......where ever you want to hook it.....", "tiles_function" ); function tiles_function() { // Try to get all the top posts in a single query $first_posts = get_posts( array( 'category' => array( 6, 7, 8 ) ); // Then get all the posts that should end up last $last_posts = get_posts( array( 'category' => 5 ); // Merge the 2 arrays of posts, first posts first, last posts last $posts = array_merge( $first_posts, $last_posts ); // Display the tiles! (WP Tiles 1.0 only!) the_wp_tiles( $posts ); }
Add it to your front-page.php and let me know if it works 🙂
Genesis Customization Service | Quick fixes whenever you need them ! | Contact me at Fixmysite.com !
June 21, 2016 at 1:27 am #187916hawb2000MemberThanks so much for responding.
I've tried to add that code to front-page.php and I'm receiving a syntax error, marking the ';' at the end of this line:
$first_posts = get_posts( array( 'category' => array( 6, 7, 8 ) );
I'm quite poor at php sorry, I feel like this could be an easy fix but I'm a bit lost.
Thanks again
June 21, 2016 at 1:37 am #187917hawb2000MemberNever mind I fixed the syntax error but I'm not exactly sure how, will report back soon
EDIT: I'm stuck on where to hook this to. The widget area I am trying to populate is one of three widget areas in that section. I'm trying to find instructions on using hooks this way but I'm coming up short.
Thanks again.
June 21, 2016 at 3:40 am #187923Brad DaltonParticipantWhy not make it into a shortcode and add that to a text widget in your widget area.
June 21, 2016 at 5:19 am #187925hawb2000MemberAwesome tip Brad thanks.
I used https://generatewp.com/ to help me generate the snippet to create a custom shortcode and its working perfectly.
Thanks to you both.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.