anchor to post ID Wordpress

Guys to make my modal dynamic and show different contents between different posts I need to anchor the id of the post.

These are the data I need to replace:

modal6

and

#modal6

code:

  <!--Modal: Name-->
    <div class="modal fade" id="modal6" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">

            <!--Content-->
            <div class="modal-content">

                <!--Body-->
                <div class="modal-body mb-0 p-0">

                    <div class="embed-responsive embed-responsive-16by9 z-depth-1-half">
                        <iframe class="embed-responsive-item" allowfullscreen src="<?php echo $AMC_metakey_video; ?>"></iframe>
                    </div>

                </div>


            </div>
            <!--/.Content-->

        </div>
    </div>
    <!--Modal: Name-->
    <a>
    <img class="card-img-top" data-toggle="modal" data-target="#modal6" <?php the_post_thumbnail(); ?></a>

if i could put the get_the_ID() i can fix my problem. i can fix this?

1 answer

  • answered 2019-09-21 23:32 Serghei Leonenco

    You can do this way:

    <!--Modal: Name-->
        <div class="modal fade" id="modal<?= get_the_ID() ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
    
                <!--Content-->
                <div class="modal-content">
    
                    <!--Body-->
                    <div class="modal-body mb-0 p-0">
    
                        <div class="embed-responsive embed-responsive-16by9 z-depth-1-half">
                            <iframe class="embed-responsive-item" allowfullscreen src="<?php echo $AMC_metakey_video; ?>"></iframe>
                        </div>
    
                    </div>
    
    
                </div>
                <!--/.Content-->
    
            </div>
        </div>
        <!--Modal: Name-->
        <a>
        <img class="card-img-top" data-toggle="modal" data-target="#modal<?= get_the_ID() ?>" <?php the_post_thumbnail(); ?></a>
    

    Hope it helps.