In Genesis Facebook group, a user asked an interesting question:
How would you do that semantically correct with genesis?
While this looks simple on the surface, it is actually challenging especially with the condition that text below the title is first paragraph of the Post’s content and that text below the featured image should not include the first para.
Method 1: Short and Recommended
(Added on January 19, 2016)
The benefit of using this approach is that structured data like headline and datePublished will remain intact. This can be tested at https://developers.google.com/structured-data/testing-tool/. See this comment for the background.
The idea is to insert featured image and Primary sidebar after the first paragraph.
Step 1
Add the following in child theme’s functions.php:
https://gist.github.com/8e6cd8562b0bd8f28557Step 2
Create a file named single-post.php in child theme directory having the following:
https://gist.github.com/8e6cd8562b0bd8f28557Step 3
Add the following in child theme’s style.css:
https://gist.github.com/8e6cd8562b0bd8f28557That’s it.
Single Posts that do not have featured images will continue to appear normally (with a right sidebar).
Method 2: Long and Not Recommended
Here’s the plan of action:
- Create a custom shortcode in functions file to output the URL of author page for the entry author outside the loop. This is needed because otherwise linked author will not appear as we are going to show the post info outside the loop.
- Create a template for single Posts in which
- entry header having entry title and post info are repositioned before content
- a custom function that prints the first paragraph of the current Post is hooked before content
- featured image is set to appear before content
- regex is used to find the first para in the post’s content and replace it with an empty string
- use
genesis_post_info
filter hook to replace the default post author posts link shortcode withpost_author_posts_link_outside_loop
custom shortcode
While the tutorial has been written for Genesis Sample child theme it should work with minor adjustments in any Genesis child theme.
Step 1
Add the following in child theme’s functions.php:
https://gist.github.com/95d10dace2361c6f62bcStep 2
Create a file named single-post.php in the child theme directory having the following code:
https://gist.github.com/95d10dace2361c6f62bcThe following image should help you understand how the regex is set to match the first para:
From DEVANZ Slack chat:
Step 3
Add the following in child theme’s style.css:
https://gist.github.com/95d10dace2361c6f62bcReferences:
http://wordpress.stackexchange.com/a/61280/14380
https://gist.github.com/banago/4023646
http://wordpress.stackexchange.com/questions/51741/get-post-content-from-outside-the-loop
http://www.codecheese.com/2013/11/get-the-first-paragraph-as-an-excerpt-for-wordpress/
http://www.regular-expressions.info/modifiers.html
https://sridharkatakam.com/post-authors-link-outside-the-loop-in-genesis/
Would it be possible to implement this with Sixteen Nine Pro Theme using ‘content-sidebar’? I’ve attempted; but haven’t had luck.
Yes. I just tested Method 1 and it works fine in Sixteen Nine Pro.
https://www.youtube.com/watch?v=TBdbBox5wOE
You just need to adjust the CSS: http://pastebin.com/raw/Uf34SmVi
How would I accomplish this using the secondary sidebar? I tried swapping in get_sidebar( ‘sidebar-alt’ ); but no luck
Oops – it’s supposed to be get_sidebar( ‘alt’ );