Community Forums › Forums › Archived Forums › Design Tips and Tricks › Need to edit this modified Loop
Tagged: genesis_custom_loop, wp_trim_excerpt
- This topic has 5 replies, 2 voices, and was last updated 8 years, 7 months ago by Toby39.
-
AuthorPosts
-
June 12, 2016 at 8:54 am #187428Toby39Participant
Hi guys,
I have a Loop used in a WP template file, that I created some time ago.
It's used in a WP Template file to change the way that Category Loop pages display the summary list of posts.The problem with it, is I need it to include the first para of the posts, along with the featured image in the form of a small square image to the left of the text - and not a giant full-width image above the text.
This is what I have so far. This is the entire contents of a file called category-business.php
It only shows the titles of the various posts under the category:<?php /** * A Simple Category Template */ define( 'WP_USE_THEMES', false ); get_header(); ?> <?php // Check if there are any posts to display if ( have_posts() ) : ?> <div class="content"> <div class="entry"> <h1><?php single_cat_title( '', true ); ?></h1> <?php // Display optional category description if ( category_description() ) : ?> <div class="archive-meta"> <p>Lorem ipsum ...</p> <p class="black-bold-para">Check out the list of <?php single_cat_title(''); ?> blog posts below</p> </div> <?php endif; ?> <?php // The Loop while ( have_posts() ) : the_post(); ?> <p class="php-list"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?> </div></div> </section> <?php get_sidebar(); ?> <?php get_footer(); ?>
I find that if I just use the standard Loop in Genesis (not the above code), the page displays each featured image full-width above each post title and then body text up to the point where <!--more--> is added within the post.
The way the text is displayed is fine, but I need the image smaller and moved to the left, and the Title and Para to the right of it (aligned left).
Any help offered would be greatly appreciated, as I am not strong in PHP.
Thanks for reading.
June 12, 2016 at 4:08 pm #187451Brad DaltonParticipantYou don't need all that code in the file.
1. You can look at the code in loops.php to see how its done or you can add the_excerpt to the code and control the length of the_excerpt.
2. You can use the genesis_custom_loop function to build your own loop which includes the standard markup
3. Or use the genesis_custom_loop_args filter to pass in your $args.
You can then modify the length of the excerpt using PHP code and use CSS or PHP code to align your image. PHP would be the most efficient.
There's 3 filters you can use to modify the size and alignment of the featured image. Look in image.php for:
genesis_get_image_default_args genesis_pre_get_image genesis_get_image
June 14, 2016 at 2:47 pm #187542Toby39ParticipantThanks Brad,
loops.php seems to have a lot of code in it.Assuming that this is the paragraph I need to edit:
function genesis_custom_loop( $args = array() ) { global $wp_query, $more; $defaults = array(); /** For forward compatibility **/ $args = apply_filters( 'genesis_custom_loop_args', wp_parse_args( $args, $defaults ), $args, $defaults ); $wp_query = new WP_Query( $args ); /** Only set $more to 0 if we're on an archive */ $more = is_singular() ? $more : 0; genesis_standard_loop(); /** Restore original query **/ wp_reset_query(); }
...what part would I edit in order to move the featured image and title, for example?
Sorry, I find I keep asking questions about PHP because I don't really know how to write it, compared to HTML and CSS which I find much easier.
June 15, 2016 at 1:44 am #187565Brad DaltonParticipantYou never edit the code in Genesis.
You'll need to search for a tutorial which includes the exact code.
Otherwise, it would take a bit of work to write the code.
June 15, 2016 at 1:48 am #187567Brad DaltonParticipantTry something like this http://wpsmith.net/2011/how-to-write-a-genesis-custom-loop-for-specific-categories-in-a-genesis-page-template/
Then you can reposition the image using code to remove and then add back the image in a different hook position or reposition the title
June 16, 2016 at 2:58 pm #187709Toby39ParticipantThanks Brad,
I have this code now, thanks to your suggestion:
<?php /** * * Template Name: Projects * This file handles blog posts with the category Projects within a page. * * SOURCE: http://wpsmith.net/2011/how-to-write-a-genesis-custom-loop-for-specific-categories-in-a-genesis-page-template/ */ remove_action(‘genesis_loop’, ‘genesis_do_loop’); add_action(‘genesis_loop’, ‘custom_do_cat_loop’); function custom_do_cat_loop() { global $query_args; // any wp_query() args echo "testing php"; $args= array('cat' => ’10’); genesis_custom_loop(wp_parse_args($query_args, $args)); } genesis(); ?>
I tried to add HTML or something between the brackets after custom_do_cat_loop but it just caused the page to fail. (not shown above)
I added the above code in the hope that testing php would show up on the page, but it did not.
Ideally I'd like to move the <h1 class="entry-title to the right, so there is more room for the featured image in the left. At the moment in The Loop, the title is above the left aligned featured image and the excerpt body text on the right.Current situation:
Ideal:
Any code suggestions welcome.
Thanks again
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.