Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Css Class to Function?
- This topic has 5 replies, 2 voices, and was last updated 10 years, 2 months ago by Davinder Singh Kainth.
-
AuthorPosts
-
February 14, 2014 at 9:34 pm #90425HawkeyeParticipant
I've added a function to my (local) site and the output is showing up where I want it, but I need to be able to style the text it contains in order to locate it correctly on the page. I tried every goofy way I could think of to hack the following code, but I'm just not sure how to add a class to PHP. (Since I'm probably using words like class and function incorrectly this may not be a shock to you.]
I'm 42.6% sure I need to add something between the parens after the words "is_single", but even if I've got that right I still don't know how to declare what the new class would be.
function next_previous_after_posts() { if ( is_single() ) { ?> <?php previous_post('« « %', '', 'yes'); ?> | <?php next_post('% » » ', '', 'yes'); ?> <?php } } add_action('genesis_entry_footer', 'next_previous_after_posts');
Any help appreciated,
Mark
February 15, 2014 at 1:44 am #90449Davinder Singh KainthMemberTry this, (you will get idea to implement class from following code)
add_action('genesis_entry_footer', 'custom_pagination_links', 15 ); function custom_pagination_links() { if( !is_single() ) return; previous_post_link('<span class="single-post-nav previous-post-link">%link</span>', '<i class=\'fa fa-arrow-circle-o-left\'></i> ' . get_previous_post_link('%title') , FALSE); next_post_link('<span class="single-post-nav next-post-link">%link</span>', get_next_post_link('%title') . ' <i class=\'fa fa-arrow-circle-o-right\'></i>' , FALSE); }
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis ThemesFebruary 15, 2014 at 11:17 am #90490HawkeyeParticipantHi Davinder,
Thanks for replying. I added this to functions.php but I was still unable to style the displayed text with CSS.
(I usually test that just by trying to draw a border/box around the text to make sure I've got control over it.)
Can you (or anyone else) point me to reference materials that cover that subject? I've looked it up every way I can on the web but I'm clearly unfamiliar with the appropriate terminology. In looking at other lines of code in my functions.php file I can see several different ways that classes are declared, but I still haven't found a simple way to add such a declaration to the code I pasted in above.
Thanks,
Mark
February 15, 2014 at 11:32 am #90497HawkeyeParticipantAfter poking around the web a little more I think the code I pasted in above is actually javascript with some PHP added, so maybe what I'm looking to do is add a css class to the javascript part. Or not.
As you can see, I'm a bit out of my element here. (Pun intended.) 🙂
February 15, 2014 at 12:31 pm #90506HawkeyeParticipantOkay, got it -- and as often happens I did so simply copying something else on the site that was already working. In this case the AddThis menu code, which showed me how to add a "div" to the code I originally pasted in above.
Here's what worked for me:
add_action('genesis_after_entry', 'next_previous_after_posts', 5); function next_previous_after_posts() { if ( is_single() ) { ?> <div class="testclass"> <?php previous_post('« « %', '', 'yes'); ?> | <?php next_post('% » » ', '', 'yes'); ?> </div> <?php } }
This now adds links for the next and previous posts just after the meta information at the bottom of single-page entries. You can change the class name to anything you want, create a CSS element with that same name and control how the links display on the page. (Also added a '5' to the original code for timing: not sure what that does, but it was important in terms of specifically where the links appeared in the document page.)
February 15, 2014 at 11:38 pm #90591Davinder Singh KainthMemberGreat, thanks for sharing final code.
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.