Community Forums › Forums › Archived Forums › General Discussion › Adding a custom shortcode to the Genesis Post Info
Tagged: entry-meta, genesis, modified date, post-date, shortcode
- This topic has 2 replies, 2 voices, and was last updated 10 years, 9 months ago by Stefsull.
-
AuthorPosts
-
February 14, 2014 at 4:06 pm #90365StefsullMember
I've googled and tried several things. Nothing is working so I'm gonna need help from one of you wizards. My designer wants the post meta to contain:
Category | Modified date | Comments/No Comments
I took the easy way out and used Genesis Simple Edits to make it happen, and it ALMOST worked — meaning, it worked as long as I wanted to use the date the post was created on, not the date it was modified on.
I created a custom shortcode for the modified date (in my functions.php file):
// Add custom shortcode for [post_modified_date] function modified_func( $atts ){ return the_modified_date(); } add_shortcode( 'post_modified_date', 'modified_func' );
However, I can't make that work in the Simple Edits plugin (that I can find anyway). My shortcode works, but it renders outside the .entry-meta instead of inside it where the [post_date] did (and where I put it in the Simple Edits plugin).
So I'm sure I need to move the whole kit and kaboodle into my functions.php and out of Simple Edits. My problem is syntax. I can get this far:
// Show modified date instead of created date remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); add_action( 'genesis_entry_header', 'custom_post_info' ); function custom_post_info() { }
But nothing I do INSIDE those pretty little brackets renders what I want. I'd rather not have to redo that whole entry-meta area, but I reckon that since I'm customizing it already, I'm going to have to. If I do have to write a function to replace the whole entry-meta, how do I intersperse the shortcodes with the actual HTML (so that the shortcodes don't render AS HTML text?
What I have is this:
<p class="entry-meta"><span class="entry-categories">Topic: <a href="http://support.contatta.com/category/general/" title="View all posts in General" rel="category tag">General</a></span> | Modified on: <time class="entry-time" itemprop="datePublished" datetime="2013-10-02T22:38:40+00:00">October 2, 2013</time> <span class="entry-comments-link"><a href="http://support.contatta.com/how-do-i-invite-a-new-user-to-contatta/#respond">No Comments</a></span></p>
What I want is something like:
<p class="entry-meta"> [post_categories sep=", " before="Topic: "] | Modified on: [post_modified_date] [post_comments zero="No Comments" one="1 Comment" more="% Comments"] </p>
Can someone point me in the right direction? (And I DO want to keep my modified-date in the <time tag for the markup.)
Cheers
http://support.contatta.comFebruary 15, 2014 at 1:03 am #90445TomParticipantHi Stefsull,
This works. You'll have to tweak to setup the html and order the elements you want. First take out your shortcode and deactivate Simple Edits.From Chris Lema: ... we find a comment from Brad Dalton that gets us to the code snippet we want from Greg Rickaby. Brad maintains this in a Gist here: https://gist.github.com/braddalton/6445390
Hope this is what you're looking for.
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]February 15, 2014 at 6:29 pm #90549StefsullMemberThank you SO much, Tom. That totally sent me down the right path... in case anyone else wants to do something similar, I'll paste my final code here:
//* Use modified date instead of published date remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); add_action( 'genesis_entry_header', 'modified_post_info' ); function modified_post_info() { if ( is_page() || is_search() ) return; // don't do post-info on pages ?> <div class="entry-header entry-meta"> <span class="entry-categories">Topic: <?php echo the_category( $separator =', ' ) ; ?></span> | <span class="date published time">Modified on: <time class="entry-date" itemprop="startDate" datetime="<?php echo the_modified_date( 'c' ); ?>" pubdate><?php echo the_modified_date(); ?></time></span> | <span class="entry-meta-comments"><a href="<?php the_permalink() ?>#comments"><?php comments_number( 'Leave a Comment', '1 Comment', '% Comments' ); ?></a></span> </div> <?php }
Again, thanks!
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.