Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add excerpt after page / post entry-title
- This topic has 6 replies, 2 voices, and was last updated 10 years, 11 months ago by Brad Dalton.
-
AuthorPosts
-
May 16, 2013 at 9:05 pm #41302csbeckMember
I'm using Agency and I would like to show some text below the page's/post's title - only on their individual page/post.
I was thinking I could put the excerpt there or some custom field text by creating a new single-page and single-post template or by using a hook. The only other way I can think of for doing what I want to do, is to create a styled paragraph. Which I can do. But I'm wondering if doing it with the excerpt and hook or template might be better. Has anyone done something like this or at least can someone make some suggestion?
Development site: http://acquireb2bdev.com/
Thanks much! Chris
http://acquireb2bdev.com/May 16, 2013 at 9:20 pm #41304Brad DaltonParticipantMay 17, 2013 at 5:51 am #41335csbeckMemberThis is great Brad. I'll give it a try.
With this hook in there, how would I dynamically pull the excerpt or custom field content into this section?
Would I?:
- Create a custom field on the page (I could call the custom field "thispage_excerpt")
- Add content (value)
- Then in your code put something like:
- echo '<div class="single-title"><?php the_meta(); ?></div>';
May 17, 2013 at 2:31 pm #41429csbeckMemberYour code needed another set of curly brackets to encase the statement within the if statement. Then the text showed up just like I wanted!
But now I want to add some dynamic text there so different pages could show different text and I'd like to modify that from the page.
OK, so here's the code that I put in my functions.php:
function after_title_text() {
if(is_page() ) {
echo '<div class="thispage_excerpt"><?php the_meta(); ?></div>';
}};
add_action('genesis_after_post_title', 'after_title_text');I've also added a custom field on my test page: http://acquireb2bdev.com/products
Key: Page ExcerptValue: This is my excerpt.
When I test the page out, the div exists on the page but the content doesn't. I'm afraid that I'm doing custom fields incorrectly. Can regular pages not have custom fields? Can you give any further advice?
Thanks, Chris
May 17, 2013 at 3:01 pm #41431Brad DaltonParticipantHi @csbeck
I tested my code before I embedded it here and it works.
I also tested it again now and it stills works.
I am fully aware it doesn't include the braces which I normally add to PHP code when hooking in widgets, but it doesn't need the braces when echoing in basic text.
1. Firstly, when pasting code in this forum, please use the PHP shortcodes. You can learn more in FAQ No.5
2. When copying PHP code from a embedded snippet, use the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++.
If you use the WordPress theme editor, the apostrophes can change and cause errors.
I'd suggest you post your second question as a new thread.
Personally, I have never used custom fields and prefer pure PHP code as its cleaner and easier to manage. Why complicate things which result in less efficiency?
I'll try to find you a solution using PHP without the custom fields.
Thank you.
May 17, 2013 at 4:02 pm #41439csbeckMemberHi Brad,
Thanks so much for both your FAQ suggestion and looking into a solution. I will do better at posting code now.
As for your code, your code does work, I was incorrect and I apologize. But it didn't work on the PAGE where I was looking because a single PAGE is not identified as "single". So your code didn't affect my test PAGE. Now I went to a post and there is your text. So thanks for getting that to me. I hope you don't take offense at my responses due to my ignorance and less experience of PHP - which I'm attempting to improve upon - I'm more of a designer.
If anyone cares, I've modified the code to be this so that it will appear on both PAGES and POSTS:
function after_title_text() { if(is_page() || is_single() ) echo '<div class="single-title">Add content after your titles but before your content here</div>'; }; add_action('genesis_after_post_title', 'after_title_text');
So thanks again and your searching for an alternative is very much appreciated.
Though I don't understand why I would need to create a separate thread; I still feel the solution to this (be it PHP, shortcodes, or custom fields) would be associated to my original question, I will create a separate thread.
Thanks! Chris
May 17, 2013 at 6:43 pm #41452Brad DaltonParticipantThanks for the code Chris and explanation about the different conditional tags which effect pages and posts.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.