• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adding dynamic buy now button to pose excerpt

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Adding dynamic buy now button to pose excerpt

This topic is: not resolved

Tagged: child theme, excerpts, modals, read more

  • This topic has 12 replies, 2 voices, and was last updated 10 years, 11 months ago by Ren Ventura.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • December 5, 2014 at 6:17 am #133688
    GabeVelez
    Participant

    This is a custom child theme that I've put together, but I need a little help.

    So I hacked together a "buy now" button next to a "read more" button on the homepage excerpt.
    This page opens up a modal window on the website.

    within my functions.php file:

    function excerpt_read_more_link($output) {
    global $post;
    return $output . '<div class="one-fourth buynowbtn">Buy Now</div>

    <div id="small-dialog" class="zoom-anim-dialog mfp-hide">
    <p>hey there - testing</p>
    </div>

    ID) . '"><div class="one-fourth readmorebtn">Read More</div>';
    }
    add_filter('the_excerpt', 'excerpt_read_more_link');

    The buttons show and the modal works! Problem is that I need the modal to open to a php file within my child theme that dynamically spits out a form. This php file that does this works perfectly - it's already working on posts already. Issue is that being that I'm using a return I can't seem to get this PHP include injected into that HTML. I've gotten this far, but not there yet with my PHP. Any thoughts?

    Gabe

    http://nycnewyears.com/
    December 5, 2014 at 6:41 am #133694
    GabeVelez
    Participant

    to clarify the code:

    function excerpt_read_more_link($output) {
     global $post;
     return $output . '<a href="#small-dialog" class="popup-with-zoom-anim"><div class="one-fourth buynowbtn">Buy Now</div></a>
    
    		<div id="small-dialog" class="zoom-anim-dialog mfp-hide">
    		<p>hey there - testing</p>
    		</div>
    
    <a href="'. get_permalink($post->ID) . '"><div class="one-fourth readmorebtn">Read More</div></a>';
    }
    add_filter('the_excerpt', 'excerpt_read_more_link');
    December 5, 2014 at 3:20 pm #133731
    Ren Ventura
    Member

    If I'm understanding correctly, you want to add a custom area to the end of a post's excerpt. Inside that custom area should be some basic markup that contains the content of an external PHP script. If that's correct, try something like this.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    December 5, 2014 at 8:31 pm #133767
    GabeVelez
    Participant

    This worked like a charm! thanks!!!

    Now I got a new problem - my own "myscript.php" file is spitting out only the form of the first excerpt on the homepage on every buy now button lol:

    <?php 
    if (get_post_meta($post->ID,'ticketCompany', true) == 1) {
    	// START: FIRST TICKET WIDGET -->
    	include_once(get_stylesheet_directory() . "/first/api-call.php");
    	// END: FIRST TICKET WIDGET -->  
    	
    } else if (get_post_meta($post->ID,'ticketCompany', true) == 2) {
    
        // START: SECOND TICKET WIDGET -->
      	include_once(get_stylesheet_directory() . "/second/api-call.php");
        // END: ELECTROSTUB TICKET WIDGET -->       
    
    } else {
    	echo "Call for more info";
    }
    ?>

    Any help again is more than appreciated 🙂

    Gabe

    December 5, 2014 at 11:05 pm #133785
    Ren Ventura
    Member

    So it's only working on the first post? Do you have any further conditionals in your template that could be interfering?

    You may also be having an issue because you're comparing the value of your meta key to an integer. The third argument in get_post_meta() is set to true so the function is returning the value as a string (see http://codex.wordpress.org/Function_Reference/get_post_meta). I obviously can't be sure on this without knowing the values of ticketCompany.

    Also, just as a small tip, you should pull out get_post_meta($post->ID,'ticketCompany', true) from your if statements, store it in a variable and compare the variable. This will prevent repetition (DRY).


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    December 5, 2014 at 11:48 pm #133788
    GabeVelez
    Participant

    Thanks Ren for your help - what's going on is that all of this came to me after the theme was built, so I just used custom fields to solve the problem rather than any custom post types. Though I'd clarify my frame of thought.

    ticketCompany is a simple value they input to identify the company. For example, if this venue uses company #1 for their e-commerce, they would input the number 1. Number 2 for company #2. Else, it echos a message to call them for info. They are familiar with which company goes through which gateway.

    The api calls pick up another custom field value, ticketID, which tells it which info to populate:
    $eventapi_id = get_post_meta($post->ID,'ticketcodenumber', true);

    This code as it stands above works perfectly on the posts. No issues there.

    What I'm assuming it may be is that being that this modal is on every excerpt, it is just reading only the first it comes across an uses that one.

    December 6, 2014 at 7:59 am #133801
    Ren Ventura
    Member

    It's hard to pinpoint the exact issue without seeing the theme files and admin because it could be a few things. Since it's outputting the same thing for every post, it seems that there may be something up with the conditional but nothing is standing out to me at this point. Also, since the content isn't being populated dynamically, there may be something in the templates as well.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    December 6, 2014 at 6:23 pm #133857
    GabeVelez
    Participant

    I still don't have the answer, but here's a thought:

    The form that's being output on these modals on the homepage are based on the FIRST post on the page. I had a plugin, Advanced Post Types Order, allowing my client to change around the order of these excerpts. Upon disabling it, the order completely changed, and the modal outputs a DIFFERENT form, because the FIRST post listed was different. Again, the same form on all the others.

    My thoughts is that it is running on the first post ID it sees on the blog page and just does that one, rather than finding the post ID related directly to it...

    Any thoughts?

    Gabe

    December 6, 2014 at 7:09 pm #133858
    Ren Ventura
    Member

    That's a strong possibility. It sounds like you're on the right track. Take a look at all of the files that are involved in outputting the form in the modal and see if you can find anything that would indicate limiting the output based on the values of the first post. Unfortunately, I cannot be more specific without seeing the files. If you would like to throw the child theme on GitHub, I (or someone else) can have a peek.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    December 9, 2014 at 9:23 am #134081
    GabeVelez
    Participant

    Hey Ren,

    I really wanted to just say thanks - a friend of mine helped me out and came up with this solution:

    add_filter( 'the_excerpt', 'my_custom_excerpt' );
    function my_custom_excerpt( $output ) {
    global $post;
    ob_start();
    include 'myscript.php';
    $script_content = ob_get_contents();
    ob_end_clean();
    $custom_excerpt = '
    <a href="#small-dialog-'.$post->ID.'" class="popup-with-zoom-anim"><div class="one-fourth buynowbtn">Buy Now</div></a>
    <div id="small-dialog-'.$post->ID.'" class="zoom-anim-dialog mfp-hide">' . $script_content . '</div>
    <a href="' . get_permalink( $post->ID ) . '"><div class="one-fourth readmorebtn">Read More</div></a>
    ';
    return $output . $custom_excerpt;
    } 

    This was the pop-up I was using: http://dimsemenov.com/plugins/magnific-popup/

    I just wanted to share - thanks again for all your help!!!

    December 9, 2014 at 10:51 am #134087
    Ren Ventura
    Member

    Glad you got it working. However, was the solution something different? What you included above as the code your friend came up with appears to be an exact copy of the gist I shared earlier.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    December 10, 2014 at 3:56 pm #134221
    GabeVelez
    Participant

    The only difference was that there was a post ID issued to the small dialog div, so it was able to recognize on a per post basis. This added specificity in detecting the proper form. Ironically, one of the forms API calls is being rewritten at the very last minute on the merchant's end due to bugs, so I had to scrub the button for now. Again, thanks for your help - you really put me in the right direction!!!

    December 10, 2014 at 4:04 pm #134223
    Ren Ventura
    Member

    Gotcha! I'm glad to have helped.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

  • Author
    Posts
Viewing 13 posts - 1 through 13 (of 13 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble