Community Forums › Forums › Archived Forums › General Discussion › How to : permanent text at top of blog page
Tagged: hooks, pin to top
- This topic has 15 replies, 4 voices, and was last updated 9 years, 2 months ago by Ren Ventura.
-
AuthorPosts
-
December 31, 2014 at 8:35 am #135746AnnamarieParticipant
I suspect that this is where a hook would come in but I'm not sure?
Basically I have a blog page (Gently Bytes) that is NOT my home page. I'd like to have about four sentences of explanatory text a the top. This could be done how? At the moment I have the first post..
"Pin" to the top a post?
Add text via hook? - how to do that? If so where does hook actually get written? I used to use Thesis.. don't know how to do it in Genesis.
Find a plugin? Is there one?All help appreciated.
Site not yet complete. to get in: tobias621
http://patientsympatheticcoaching.comDecember 31, 2014 at 10:08 am #135748arushMemberHi,
You can add text to the top of the blog template like this:
1. Copy the page_blog.php template from the root of the Genesis folder.
2. Add it to your child theme's folder.
3. Add the following line just above genesis(); add_action( 'genesis_loop', 'genesis_standard_loop', 5 );
4. Add text to the page by editing it in the pages screen of your wp-admin.Hope this helps,
Amanda
December 31, 2014 at 10:11 pm #135779Ren VenturaMemberActually this is quite simple. Just determine where you want your content to appear and hook into that action. For locations, see the Genesis Visual Hook Guide. Also, this prevents having to override core Genesis templates.
http://genesistutorials.com/visual-hook-guide/category/category-1/
Let's say you want to use genesis_before_content hook. Your code would look something like this (including a conditional to only show it on the main blog page):
add_action( 'genesis_before_content', 'rv_echo_custom_blog_text' ); function rv_echo_custom_blog_text() { if ( is_home() ) { echo 'My custom text goes here.'; } }
This would go in your functions.php.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 1, 2015 at 6:03 am #135790Brad DaltonParticipantThere's many ways to do this.
Here are 2:
1. You can create a custom blog page template
2. Or use a hook to add text before your posts
January 2, 2015 at 11:47 am #135865AnnamarieParticipantI tried the direct hook method. (Since I don't need to change this text, I'm thinking.)
Something's not right as the text isn't displaying. I don't really know PHP but I've messed around in it before. I made the function "introtext_before_posts".. and am trying to call the page. I have the posts page set to "Gentle Bytes" (in Settings/Reading) .. my guess is that I've got the wrong call..? i've tried the following: posts, 86, gentle-bytes. I'm out of ideas. Can someone tell me what's wrong? here's the page: http://patientsympatheticcoaching.com/gentle-bytes/
Thanks for the help.
//*coding to put permanent text at top of posts*// function introtext_before_posts() { if ( is_page( '086' ) ) echo '<div class="before-blog">Gentle Bytes expresses my intent to offer you basic information about computers, tablets and smartphones in simple and clear terms. Gently. My hope is that you will learn so that you gain control of your device and can use it with pleasure. This is not for geeks. This blog and newsletter is for the generation that had a childhood and higher education with typewriters, card catalogs, and mimeograph machines. (Remember the smell of freshly printed mimeos?)</div>'; }; add_action('genesis_before_loop', 'introtext_before_posts');
January 2, 2015 at 12:56 pm #135867AnnamarieParticipantI tried Amanda's method and also the custom blog page method. None of them are displaying my text! I'm sure it has to do with properly identifying the page? But how?
January 2, 2015 at 1:28 pm #135868Ren VenturaMemberYour page ID is probably wrong (I've never seen a 3 digit ID that starts with a 0). To get the page ID, you have a few options. You can hover over "Preview Changes" and look at the link or do something like install the Simply Show IDs plugin (https://wordpress.org/plugins/simply-show-ids/) to add a column that shows the post ID. Also, instead of the ID, you can just use the page slug ('gently-bytes' in your case). Here's a cleaned-up version of what you had that uses the slug:
//* coding to put permanent text at top of posts add_action( 'genesis_before_loop', 'introtext_before_posts' ); function introtext_before_posts() { if ( is_page( '086' ) ) { echo '<div class="before-blog">Gentle Bytes expresses my intent to offer you basic information about computers, tablets and smartphones in simple and clear terms. Gently. My hope is that you will learn so that you gain control of your device and can use it with pleasure. This is not for geeks. This blog and newsletter is for the generation that had a childhood and higher education with typewriters, card catalogs, and mimeograph machines. (Remember the smell of freshly printed mimeos?)</div>'; } }
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 2, 2015 at 2:21 pm #135871AnnamarieParticipantYeah! All fixed. Right the "O" was stupid. But I had tried '86' - did it have to be a three digit ID? You put the "add_action.." line above the function creation (if that's what you call it) was that important to getting it working? I'd always seen the other way (in Thesis)
thanks so much!
January 2, 2015 at 2:26 pm #135872AnnamarieParticipantSpoke too soon. It worked once and now isn't . Sigh.
January 2, 2015 at 2:39 pm #135873Ren VenturaMemberIt doesn't matter where you place the add_action() as long as it's there. I prefer to put it above the function so I can see what I'm doing with the function before I read it. It's just a matter of preference.
I apologize as I somehow forgot to change the is_page() portion in my last reply (I didn't change '086' to the slug). Try this:
//* coding to put permanent text at top of posts add_action( 'genesis_before_loop', 'introtext_before_posts' ); function introtext_before_posts() { if ( is_page( 'gentle-bytes' ) ) { echo '<div class="before-blog">Gentle Bytes expresses my intent to offer you basic information about computers, tablets and smartphones in simple and clear terms. Gently. My hope is that you will learn so that you gain control of your device and can use it with pleasure. This is not for geeks. This blog and newsletter is for the generation that had a childhood and higher education with typewriters, card catalogs, and mimeograph machines. (Remember the smell of freshly printed mimeos?)</div>'; } }
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 3, 2015 at 7:19 am #135912AnnamarieParticipantHmm.... I didn't see your answer until this AM. I tried that too. What's weird is that it did do it ONCE - long enough for me to format the CSS. There must be something conflicting with the function?
Just to be incredibly sure.. I'm putting this code in wp-content/themes/genesis-sample/functions.php. Right?
(yes I started building with the sample child theme)
And here is my code cut and pasted..//* coding to put permanent text at top of posts add_action( 'genesis_before_loop', 'introtext_before_posts' ); function introtext_before_posts() { if ( is_page( 'gentle-bytes' ) ) { echo '<div class="before-blog">"Gentle Bytes" offers you basic information about computers, tablets and smartphones in simple and clear terms. Gently. You will learn to gain control of your device and use it with pleasure. This is not for geeks. This blog and newsletter is for the generation that had a childhood and higher education with typewriters, card catalogs, and mimeograph machines. (Remember the smell of freshly printed mimeos?)</div>'; } }
Any further thoughts?
January 3, 2015 at 1:24 pm #135938Ren VenturaMemberYou're correct in placing the code in your functions.php. It's strange that it would work and just stop without giving you any errors.
Did it stop working after you added the CSS? Remove the div tags and see if that fixes the problem.
If you confirm that the CSS is not the issue, try using another hook to see if the text outputs elsewhere. For example, genesis_before_content.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 3, 2015 at 4:39 pm #135943AnnamarieParticipantHmm... I keep wondering if there's something really basic that I'm not doing?
Neither suggestion worked: The removing of the divs (you meant in the code the functions.php file yes?)
Nor hooking the text with anything else. I think I'm not picking up the page - and that's because I called it something different than blog? I've put in a trouble ticket with Studio Press, referencing this conversation.
Thanks for help!
January 3, 2015 at 5:23 pm #135945Ren VenturaMemberSo is this your blog index or a Page? I assumed it was a page since you changed the is_home() from my first reply to is_page(). However, if it's your blog index, you will need to use is_home() even though you've created the Page and set it to display your posts. I know it isn't very intuitive on the surface but is_home() returns true for your main blog index, even though it's a Page.
If that doesn't work, you might need to have a developer take a look at your site so they can see everything and figure out what's going on.
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
January 3, 2015 at 6:34 pm #135951AnnamarieParticipantOMG! I *KNEW* is had to be something stupid I was doing. Just goes to show how a little bit of knowledge can be dangerous. never know that "is_home" referred to the posts. Sigh! Well it's working now, many, many thanks. I've learned a lot poking about trying to understand hooks and figure out what was wrong.
All better.
Thanks!
January 3, 2015 at 9:26 pm #135958Ren VenturaMemberGlad it's working for you. You'll find that you become much more comfortable with PHP and WordPress hooks working with Genesis because it forces you to learn.
Good luck!
Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.