Forum Replies Created
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
preahkumpiiMember
I figured it out. Maybe it will help someone else.
All of the code was put into the functions.php file. I did not have to touch the single.php file.
add_image_size( 'pst-related-posts-thumb', 250, 250, array( 'center', 'top' ) ); //for related posts add_action( "genesis_loop", "pst_related_posts" ); function pst_related_posts() { if ( is_single() ) { //make sure related posts only shows on single posts $my_cats = get_the_category(); $my_cat_id = $my_cats[0]->cat_ID; //gets the current post category id; must be done in loop $args = array( //sets arguments for get_posts() function, including get only posts with current post category id 'posts_per_page' => 12, //this number should be several more than the number of posts to show 'category' => $my_cat_id, 'orderby' => 'rand' ); $posts_array = get_posts( $args ); echo "<div class='pst-related-posts'>"; echo "<h3>We think you'll love this momspiration too!</h3>"; echo "<ul>"; $count = 0; foreach ($posts_array as $my_post) { if ( !has_post_thumbnail( $my_post ) ) { continue; } //cycle through each matched post and get needed info (title, url, thumbnail, etc.) $title = $my_post->post_title; $link = get_permalink($my_post); $thumb = get_the_post_thumbnail($my_post, "pst-related-posts-thumb"); echo "<li>"; echo "<h4><a href='" . $link . "' target='_self' title='" . $title . "'>" . $title . "</a></h4>"; echo "<a href='" . $link . "' target='_self' title='" . $title . "'>" . $thumb . "</a>"; echo "<a href='" . $link . "' target='_self' title='" . $title . "'><div class='pst-related-posts-button'>Read it now →</div></a>"; echo "</li>"; $count++; if ( $count == 6 ) { //this is the number of posts to show break; } } echo "</ul>"; echo "</div>"; } }
preahkumpiiMemberThanks. I was actually hoping to streamline this process by not using a plugin. We already have dozens of plugins and I don't really want to add to the bloat. So I'm hoping for a code snippet with the basics...
Adam
February 19, 2016 at 4:37 pm in reply to: How to move the post title to after the post image in custom genesis grid loop? #179424preahkumpiiMemberIn home.php (also archive.php). The archive page in question is the home page.
<?php remove_action( 'genesis_entry_content', 'genesis_grid_loop_content' ); //* Add support for Genesis Grid Loop remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'child_grid_loop_helper' ); function child_grid_loop_helper() { if ( function_exists( 'genesis_grid_loop' ) ) { genesis_grid_loop( array( 'features' => 0, 'feature_image_size' => 'full', 'feature_image_class' => 'grid-first-featured', 'feature_content_limit' => 500, 'grid_image_size' => 'grid-thumbnail', 'grid_image_class' => 'grid-featured', //'grid_content_limit' => 100, 'more' => __( 'Continue Reading', 'genesis' ), ) ); } else { genesis_standard_loop(); } } genesis(); ?>
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)