Community Forums › Forums › Archived Forums › Design Tips and Tricks › Making entire post entry clickable – Genesis Framework
- This topic has 4 replies, 1 voice, and was last updated 11 years, 3 months ago by lucaslem.
-
AuthorPosts
-
September 30, 2013 at 3:43 pm #64841lucaslemMember
I tried to post about this a few days ago, but I think the title and everything got mangled with the code tags, and what I was trying to achieve was not so clear. I'm attempting to make it clearer here; my apologies in advance if there is a more appropriate way to handle this sort of mishap.
I am working from a custom child theme (Gen Framework HTML 5). I have set up my loop to display the title and excerpt. I am attempting to add markup so that the entire entry is clickable rather than only being able to click on either the entry title or "read more" link from the excerpt. Here is an example which illustrates what I am trying to achieve.
Using the Genesis code snippets I have managed to remove the parts I don't need (post meta, read more link etc), however I am not sure how to handle the PHP in order to modify the remaining markup to suit my needs.
Currently I have this:
<article class="post-### ... " itemscope="itemscope" itemtype="http://schema.org/CreativeWork"> <h1 class="entry-title" itemprop="headline"> <a href="http://permalink" title="Title" rel="bookmark">Title</a> </h1> <div class="entry-content" itemprop="text"><p>excerpt in here</p></div> </article>
In order to make the entire block clickable, I would like to change the markup like so:
<article class="post-### ... " itemscope="itemscope" itemtype="http://schema.org/CreativeWork"> <a class="myclass" href="http://permalink"> <h1 class="entry-title" itemprop="headline">Title</h1> <div class="entry-content" itemprop="text"><p>excerpt in here</p></div> </a> </article>
I am unsure if this is a simple case of adding some code to the function i used to remove the post meta, or if this requires a custom loop. Either way, all help or resources are appreciated.
Thanks
October 1, 2013 at 2:45 pm #64986lucaslemMemberAnyone have ideas on this? What hooks can I use to add the necessary mark-up? So far neither genesis_before_entry_header nor genesis_after_entry_content seem to work. My code:
function ismh_open_article_link_tag() { echo '<a href ="' . get_permalink() . '">'; } add_action('genesis_before_entry_header', 'ismh_open_article_link_tag(');
function ismh_close_article_link_tag() { echo '</a>'; } add_action('genesis_after_entry_content', 'ismh_close_article_link_tag');
October 2, 2013 at 8:12 am #65063lucaslemMemberOk, I have managed to get this working with these two functions:
add_action('genesis_before_entry_content', 'ismh_open_article_link_tag'); function ismh_open_article_link_tag() { if( is_post_type_archive( 'workshops' ) ) { echo '<a href ="' . get_permalink() . '"> <h1 class="entry-title" itemprop="headline">' . get_the_title() . '</h1>'; //* Remove the entry title (requires HTML5 theme support) remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); //* Remove the entry meta in the entry header remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); //* Remove the entry meta in the entry footer (requires HTML5 theme support) remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); } }
add_action('genesis_after_entry_content', 'ismh_close_article_link_tag'); function ismh_close_article_link_tag() { if( is_post_type_archive( 'workshops' ) ) { echo '</a>'; } }
However there seems to be a bug in that the first entry in the list still display the
<header class="entry-header">
which includes the linked post title as well as the entry meta. You can see a visual representation of this in this screenshot (sorry still working locally)Does anyone have any idea what could be causing this issue on the first post? Thanks.
October 3, 2013 at 8:55 am #65204lucaslemMemberbump
October 3, 2013 at 5:15 pm #65275lucaslemMember3 days in I finally found the solution and figured I would share here for anyone else who might face the same issues. It's trial by fire here and it seemed I was missing the notion of the loop action hooks... and needing to put those in their own function to be applied conditionally. Many thanks to this blog post by Jonathan Perez!
So here's my final code:
//* 1. Conditionally remove post title, post meta and post info add_action('genesis_before_loop','ismh_workshops_no_entry_header'); function ismh_workshops_no_entry_header() { if( 'workshops' == get_post_type() && ! is_single() ) { //* Remove the entry title remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); //* Remove the entry header markup remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); //* Remove the entry meta in the entry header remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); //* Remove the entry meta in the entry footer remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); } } //* 2. Open link tag and add post title add_action('genesis_before_entry_content', 'ismh_open_article_link_tag'); function ismh_open_article_link_tag() { if( 'workshops' == get_post_type() && ! is_single() ) { echo '<a href ="' . get_permalink() . '"> <h1 class="entry-title" itemprop="headline">' . get_the_title() . '</h1>'; } } //* 3. Close link tag add_action('genesis_after_entry_content', 'ismh_close_article_link_tag'); function ismh_close_article_link_tag() { if( 'workshops' == get_post_type() && ! is_single() ) { echo '</a>'; } }
-
AuthorPosts
- The topic ‘Making entire post entry clickable – Genesis Framework’ is closed to new replies.