• The page in question: rickwolff.com/blog
    I’m trying to get functions.php to insert the words in the “excerpt” field in the database, alone (no ellipsis, no “more” text), styleable with a CSS class, underneath the title of a post (my framework, Headway, has provided me with a hook, as you can see), in only two instances: the post title in a single post page, and the first post in the blog index page.
    I am prepared to make a special field in my posts called, let’s say, “subtitle,” and populate it with the text of the excerpts manually.
    I know I’m asking the same question as https://www.ads-software.com/support/topic/custom-excerpt-text-in-functionsphp?replies=5 … but I’m more clueless than the guy who asked that question.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Basically it sounds like you just need to customize what the_excerpt() returns, then put that into your post template. I’m not sure what you mean by a hook provided by your framework. Can you post more info?

    You can probably find more info on customizing the_excerpt() in the Codex at https://codex.www.ads-software.com/Function_Reference/the_excerpt

    Thread Starter RickWolff

    (@rickwolff)

    Stephen:
    For my education: In that example in that Codex page,

    function new_excerpt_more( $more ) {return '[.....]';}
    add_filter('excerpt_more', 'new_excerpt_more');

    Line 2 is saying, “change ‘excerpt_more’ to ‘new_excerpt_more’, which I’ve defined in line 1 to be five dots in a row.” Right? So I just go {return '[]';} and it replaces it with nothing? Or are five dots interpreted as “put nothing here”? What does ($more) mean? Am I completely misunderstanding what happens here?
    The business about Headway providing me a hook: notice I’m not asking “How do I point to where in the loop I want the excerpt to appear?” because I figured out hooks. Don’t worry about it.
    Also, to make it style-able, somewhere I make it echo <div class="subtitle"> and </div>, right? It requires a deft switch from PHP to HTML and back. I can mimic from a well-written example. Got any I can link to?
    And to make it appear as a subtitle only in the first post of my blog index page and in a single post page, I use conditionals, right? Again, how do I phrase what I want to say? Any examples you can link me to?
    Yes, I’m using a forum to steal an education.

    1. return ‘[…..]’;
    will give you five dots at the end of the excerpt. You can change it into anyhting you want or remove the dots by using
    return ”; (remove the brackets and the dots)

    2. To style the excerpt output, you better go with <div class=”subtitle”><?php echo get_the_excerpt(); ?></div>

    3. – Subtitle only in the first post of blog post (index) = i don’t know how to do this.
    – Single post = your theme must be have single.php

    Well, you kind of have a relatively simple problem (for someone who knows what they’re doing) but explaining how to do the coding yourself is going to be rather pointless if you don’t already know how to code it. Your best bet for an education is to learn PHP first so that you understand the concepts.

    Nonetheless, I believe you can use {return ‘…..’;} in that code sample to use 5 dots, then save that to your functions.php file. From there, you need to edit the individual template file(s) that already exist in your theme to get the excerpt to show only on the pages you wish, surrounded by your div wrapper. Depending on what templates are provided for in your theme, you may not need to write conditional statements or you might have to use them exclusively.

    I wish I could be more specific than that, but a lot depends on whether your theme uses homepage, single post, and archive templates. If it mainly only uses a index.php file, then you’ll have to either (A)create template files for just the pages you want the excerpt to show on, or (B)use PHP conditions with is_home() and/or is_single() selectors to get the desired results with just the index.php file.

    If you break down and need someone to do it for you, I can offer a relatively inexpensive project rate, but I don’t have time to give PHP primers on forums. Hope you understand.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using excerpt as a subtitle in single posts’ is closed to new replies.