- This topic has 19 replies, 4 voices, and was last updated 5 years, 11 months ago by Tom.
-
AuthorPosts
-
February 27, 2017 at 2:13 am #284447Are Martin
Hi Tom,
I’m using the sections add-on for some blog posts and would like to display the date, author, category comments etc.. within the top section.I,ve tried some plugins that are using shortcodes to display post meta but they’re not really working that well.
Any idea how this could be achieved?
February 27, 2017 at 8:14 am #284553LeoStaffCustomer SupportHi there,
How are you currently displaying the posts in sections?
Can you provide a link to your site?
Let me know π
February 27, 2017 at 8:46 am #284572Are MartinCurrently I’m using the generatepress sections add-on. I haven’t posted any examples yet but I have a few drafts where I want to display the author, category etc.. within the section.
February 27, 2017 at 8:51 am #284580LeoStaffCustomer SupportHmm unfortunately I don’t think you can activate sections on blog page.
I would recommend using Tom’s WP Show Posts plugin to display blog posts in GP’s Sections:
https://en-ca.wordpress.org/plugins/wp-show-posts/Then there should be options to display post meta.
Let me know if this helps.
February 27, 2017 at 8:52 am #284581Are MartinI am using sections for some pages though http://www.fysionett.no/hva-er-fysioterapi/hvordan-blir-man-fysioterapeut/
This is an example of breadcrumbs inserted in the top section using shortcode. I would like to do something similar with post meta for blog posts using sections
February 27, 2017 at 8:59 am #284584LeoStaffCustomer SupportYup that page is a static page which is fine to use sections.
It’s just that sections won’t work on the page you set in Customizer > Static Front Page > Posts page.
The alternative is to use Sections on a static page and combine with WP Show Posts.Let me know if this answers the question π
February 27, 2017 at 9:32 am #284603Are MartinI think you misunderstand my question. I know this i a static page and I’m not talking about the blog page. Since a few updates ago it is actually possible to use the sections add-on with blog posts. What I would like to do is to fetch the entry-meta/post meta from the current post and display this within a section using either shortcode or a php function.
February 27, 2017 at 9:48 am #284619TomLead DeveloperLead DeveloperYou would have to create a shortcode which would output the entry meta.
add_shortcode( 'entry_meta', 'tu_entry_meta_shortcode' ); function tu_entry_meta_shortcode() { if ( ! function_exists( 'generate_posted_on' ) ) { return; } ob_start(); ?> <div class="entry-meta"> <?php generate_posted_on(); ?> </div><!-- .entry-meta --> <?php $ret = ob_get_contents(); ob_end_clean(); return $ret; }
Then you would use
[entry_meta]
.February 27, 2017 at 12:18 pm #284691Are MartinThanks Tom π ThatΒ΄s what I was looking for. However using the plugin code snippets to implement the code i get this error message:
The snippet has been deactivated due to an error on line 5:
syntax error, unexpected ‘}’February 27, 2017 at 12:21 pm #284693TomLead DeveloperLead DeveloperSorry about that! I just updated the code above.
February 27, 2017 at 12:31 pm #284701Are MartinThanks! That worked perfectly π This will be very useful for adding the entry meta below a post title within the page header as well. Perfect! π
February 27, 2017 at 12:33 pm #284702TomLead DeveloperLead DeveloperAwesome, glad I could help π
May 1, 2018 at 8:59 pm #565082MartinI added the function but when I include the shortcode on a page with sections enabled, it only shows the post date, not the author name.
Shouldn’t this function also show the author name?
May 1, 2018 at 9:43 pm #565116TomLead DeveloperLead DeveloperIt should, as long as the author is enabled in Customize > Layout > Blog.
If not, can you link me to the page?
May 1, 2018 at 10:45 pm #565128MartinI can’t link because it’s on localhost.
If I switch off sections, the HTML/PHP output by the shortcode is:
<div class="entry-meta"> <span class="posted-on"><a href="http://127.0.0.1/wordpress/sleep-restriction-therapy/" title="6:32 pm" rel="bookmark"><time class="entry-date published" datetime="2018-05-01T18:32:47+00:00" itemprop="datePublished">May 1, 2018</time><time class="updated" datetime="2018-05-02T05:47:54+00:00" itemprop="dateModified">May 2, 2018</time></a></span> <span class="byline"><span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">by <a class="url fn n" href="http://127.0.0.1/wordpress/author/martin/" title="View all posts by Martin Reed" rel="author" itemprop="url"><span class="author-name" itemprop="name">Martin Reed</span></a></span></span> </div><!-- .entry-meta -->
If I switch sections back on, the HTML/PHP output by the shortcode is:
<div class="entry-meta"> <span class="posted-on"><a href="http://127.0.0.1/wordpress/sleep-restriction-therapy/" title="6:32 pm" rel="bookmark"><time class="entry-date published" datetime="2018-05-01T18:32:47+00:00" itemprop="datePublished">May 1, 2018</time><time class="updated" datetime="2018-05-02T05:46:21+00:00" itemprop="dateModified">May 2, 2018</time></a></span> <span class="byline"><span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">by <a class="url fn n" href="http://127.0.0.1/wordpress/author/" title="View all posts by " rel="author" itemprop="url"><span class="author-name" itemprop="name"></span></a></span></span> </div><!-- .entry-meta -->
-
AuthorPosts
- You must be logged in to reply to this topic.