SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can not get the syntax right, excerpt more with post title

    Hi,
    I just can't seem to get this line right. I think I am awfully close. I am copy change and hope kind of PHP person! My code editor tells me I have a syntax error.
    PHP Code:
    return <'href="'get_permalink($post->ID) . '">' 'Continue Reading:'get_the_title() . '</a>'); 
    Just in case here is the whole function
    PHP Code:
    function new_excerpt_more($more) {
           global 
    $post;
        return <
    'href="'get_permalink($post->ID) . '">' 'Continue Reading:'get_the_title() . '</a>';
    }
    add_filter('excerpt_more''new_excerpt_more'); 

  2. #2
    SitePoint Member
    Join Date
    May 2012
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your problem is probably the "get_permalink($post->ID)" section. I'm not 100% sure what you're trying to achieve but I think it's just build a link that directs to a specifc post right?

    I achieved something similar using shortcodes like so:

    PHP Code:
    add_shortcode("addlink""add_link");  //Create [addlink] shortcode to generate button

    function settings_url() {
        
    $settings_url "/my-settings/";
        return 
    $settings_url;
    }

    //  Create shortcode to build link to register a home patient to current post
    function add_link($content null) {
        
    $url site_url() . settings_url() . "register";  //Set base url for form
        
    $parent "&home_id=" get_the_ID();  //Set variable to Wordpress function for current post id
        
    $assembled_url $url .  $parent;  //Build full url
        
    $url_class "iframeFancybox3 form-button";  //Classes to be applied to url
        
    $button_text "Add";  //Text visable on button
        
    $adddoclink '<a href="'.$assembled_url.'" class="'.$url_class.'">'.$button_text.'</a>';  //Assemble complete link
        
    return $addlink;  //Return complete link

    If that's any use. I tried doing it the way you are and it wouldn't resolve the php so I wound up doing it like this and it's working perfectly for loads of them.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the input. I am trying to replace the default [...] that is at the end of a automatic post excerpt, when there is a list of them on the blog page.
    The code below does work, I just can't seem to add the title after Continue Reading.
    PHP Code:
    function new_excerpt_more($more) {
           global 
    $post;
        return 
    ' <a href="'get_permalink($post->ID) . '">Continue reading </a>';
    }
    add_filter('excerpt_more''new_excerpt_more'); 

  4. #4
    SitePoint Member
    Join Date
    May 2012
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't get_the_title() be passed a parameter? Something like get_the_title($post->ID) perhaps?

    May sound stupid but have you tried surrounding the Continue Reading bit with " marks?

    If you look at the code I posted last time, I set the link text in the variable "$button-text". If you're having trouble try assembling it in another variable and then just call the variable as the text. That's what I always do if something isn't working, try breaking it down further and set it away from the main bit. Nested double and single quotes are a real pain so I'd try that.

    So maybe:

    PHP Code:
    function new_excerpt_more($more) { 
           global 
    $post
           
    $text "'Continue reading ' .  get_the_title($post->ID)".
        return 
    ' <a href="'get_permalink($post->ID) . '">$test</a>'

    add_filter('excerpt_more''new_excerpt_more'); 
    Beyond that I dunno I'm afraid bud.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    your idea of using a variable for the title is good. Also you are right you have to use the ID in the title if not using it in the loop.
    If you look at the color in your code you can see it still has some syntax problems line 3 and 4, oh how I hate the evil ' '
    I got it to this but the 4th line still says syntax error
    PHP Code:
    function new_excerpt_more($more) { 
           global 
    $post;
           
    $text 'Continue reading ' .  get_the_title($post->ID);
        return 
    '<a href="' get_permalink($post->ID) . '"> ' $text '</a>'

    add_filter('excerpt_more''new_excerpt_more'); 
    Thanks for a good try anyway ;-)

  6. #6
    SitePoint Member
    Join Date
    May 2012
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, sorry about that I just rattled it out for a quick example and didn't check it properly.

    Have you managed to get anywhere with this then? Also I'm sure you don't need the . before the variable, surely just "$text" would be enough?

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Finally this works in case anyone should come across this
    PHP Code:
    function new_excerpt_more($more) {
           global 
    $post;
        return 
    '<a href="'get_permalink($post->ID) . '">' ' ..Continue Reading  'get_the_title($post->ID) . '</a>';
    }
    add_filter('excerpt_more''new_excerpt_more'); 
    It was the first ' which was here <a 'href instead of here '<a href

  8. #8
    SitePoint Member
    Join Date
    May 2012
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you got it sorted bud :-)


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •