Learn how to create a loop that shows the title, excerpt and image in the order you decide for a CPT in Genesis Framework with this tutorial.
One of the advantages of being an OsomCode subscriber is that you can propose tutorials. For example, a subscriber left me this suggestion:
Well, I propose you some tutorials:
– Reposition the title of a Custom Post Type loop at the end. Maybe a after entry.
– Also, reposition several elements of Custom Post Type loops.
I mean, in the Custom Post Types loops (books, students…) it’s interesting to put first the picture, then the excerpt, then the name (title), custom taxonomies…
I think there could be several tutorials related to this topic.
In short, the idea that Guillem proposes is to modify the order of the elements of the loop (title, excerpt, featured image…) in some CPTs.
Besides, he also told me that he wanted to make it as a plugin so that the child theme changes wouldn’t alter the result.
Well, here you have how to do it. 😉
Snippet to modify the loop order of a CPT in Genesis Framework
Add the following fragment to your functionality plugin or create a new one specifically for it:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this code snippet you get to replace the WordPress loop in the CPT ‘Books’ archive page with a custom one.
The new loop will be loaded in the following order:
- Featured image
- Excerpt
- Title
If you want to modify it to your liking, just change the order of the elements in the snippet. They have a commentary on the right to make it easier for you to locate them.
On the other hand, you can also make this loop apply to other CPTs by replacing “Books” with whatever you want.
You may want to reduce the length of the excerpt with this new design. To do this, add the following code just before the last ” }”:
To see this and another 1097 code snippets of this website, login or subscribe here.
Again, you have the possibility to adjust the size of the excerpt according to your preferences by changing the number.
Conclusions
Now you know how to modify the hierarchy of the loop elements for a Custom Post Type, so that you can display the title, excerpt and featured image in the order you want.
You have the possibility to make all the combinations you want, so that they only affect the CPT you choose.
Also, by placing it in a plugin (or creating a new one), these customizations will be maintained even if you change the child theme.
Do you want me to create a variation of this tutorial?
Send me the details through the contact form so I can create a custom tutorial with your question.
Advantages of being a subscriber.