簡體   English   中英

如何將data.id存儲到php變量

[英]How to store data.id to php variable

請查看代碼,它是一個wordpress主題模板。 在獲取帖子ID時遇到問題,該問題存儲在data.id中。 當我們編寫{{data.id}}時會顯示它。

我需要在php變量中獲取此值。

我試過了:

$id = $data->id;

$id = $data['id'];

但是這些不起作用。

我需要一些東西: $id = {{data.id}};

這是原始代碼,其中第一行包含{{data.id}}

<li id="listing-{{data.id}}" class="job_listing type-job_listing card-style--default style-grid {{data.styles.cardClasses}}">
<script id="tmpl-listingCard" type="text/template">

<?php
/**
 * Insert content before a listing.
 *
 * @since 2.0.0
 */
do_action( 'listify_listing_card_before' );
?>

<li id="listing-{{data.id}}" class="job_listing type-job_listing card-style--default style-grid {{data.styles.cardClasses}}">
    <div class="content-box">

        <?php
            /**
             * Insert content at the start of the listing.
             *
             * @since Unknown
             *
             * @hooked Listify_Astoundify_Favorites::render_js() - 10
             */
            do_action( 'listify_content_job_listing_before' );
        ?>

        <a href="{{data.permalink}}" class="job_listing-clickbox"<# if ( data.cardDisplay.target) { #> target="_blank"<# } #>></a>

        <header class="job_listing-entry-header listing-cover <# if ( data.featuredImage.url ) { #>has-image<# } #>" <# if ( data.featuredImage.url ) { #>style="background-image:url({{data.featuredImage.url}})"<# } #>>

            <?php
                /**
                 * Insert content before the listing header.
                 *
                 * @since Unknown
                 */
                do_action( 'listify_content_job_listing_header_before' );
            ?>

            <div class="job_listing-entry-header-wrapper cover-wrapper">

                <?php
                    /**
                     * Insert content at the start of the listing header.
                     *
                     * @since Unknown
                     */
                    do_action( 'listify_content_job_listing_header_start' );
                ?>

                <div class="job_listing-entry-meta">
                    <# if ( data.status.featured && 'badge' === data.styles.featuredStyle ) { #>
                        <div class="listing-featured-badge">{{data.i18n.featured}}</div>
                    <# } #>

                    <# if ( data.cardDisplay.title ) { #>
                        <h3 class="job_listing-title">{{{data.title}}}</h3>
                    <# } #>

                    <# if ( data.cardDisplay.address && data.location ) { #>
                        <div class="job_listing-location">{{{data.location.address}}}</div>
                    <# } #>

                    <# if ( data.cardDisplay.telephone && data.telephone ) { #>
                        <div class="job_listing-phone">{{data.telephone}}</div>
                    <# } #>

                    <?php
                        /**
                         * Insert content after other meta information.
                         *
                         * @since unknown
                         */
                        do_action( 'listify_content_job_listing_meta' );
                    ?>
                </div>

                <?php
                    /**
                     * Insert content at the end of the listing header.
                     *
                     * @since Unknown
                     */
                    do_action( 'listify_content_job_listing_header_end' );
                ?>

            </div>

            <?php
                /**
                 * Insert content after the listing header.
                 *
                 * @since Unknown
                 */
                do_action( 'listify_content_job_listing_header_after' );
            ?>
        </header>

        <# if ( data.cardDisplay.rating || data.cardDisplay.secondaryImage || data.cardDisplay.claimed ) { #>

        <footer class="job_listing-entry-footer">

            <?php
                /**
                 * Insert content at the start of the listing footer.
                 *
                 * @since Unknown
                 */
                do_action( 'listify_content_job_listing_footer' );
            ?>

            <# if ( data.cardDisplay.rating ) { #>
                <div class="listing-stars">
                    <# if ( data.reviews ) { #>
                        <# for ( var i = 1; i <= data.reviews.stars.full; i++ ) { #>
                            <span class="listing-star listing-star--full"></span>
                        <# } for ( var i = 1; i <= data.reviews.stars.half; i++ ) { #>
                            <span class="listing-star listing-star--half"></span>
                        <# } for ( var i = 1; i <= data.reviews.stars.empty; i++ ) { #>
                            <span class="listing-star listing-star--empty"></span>
                        <# } #>
                    <# } #>

                </div>
                <div class="heading_footer">

                 </div>

            <# } #>

            <# if ( data.cardDisplay.secondaryImage && data.secondaryImage.url ) { #>
                <div class="listing-entry-company-image listing-entry-company-image--card listing-entry-company-image--type-{{data.secondaryImage.type}} listing-entry-company-image--style-{{data.secondaryImage.style}}">
                    <# if ( data.secondaryImage.permalink ) { #><a href="{{data.secondaryImage.permalink}}"><# } #>
                        <img class="listing-entry-company-image__img listing-entry-company-image__img--type-logo listing-entry-company-image__img--style-{{data.secondaryImage.style}}" src="{{{data.secondaryImage.url}}}" alt="{{data.title}}" />
                    <# if ( data.secondaryImage.permalink ) { #></a><# } #>
                </div>
            <# } #>

            <# if ( data.cardDisplay.claimed && data.status.claimed ) { #>
                <span class="claimed-ribbon">
                    <span class="ion-checkmark-circled"></span>
                </span>
            <# } #>

        </footer>

        <# } #>

        <?php
            /**
             * Insert content at the end of the listing.
             *
             * @since Unknown
             */
            do_action( 'listify_content_job_listing_after' );
        ?>

    </div>
</li>

<?php
/**
 * Insert content after a listing.
 *
 * @since 2.0.0
 */
do_action( 'listify_listing_card_after' );
?>

</script>

這是一個javascript變量,它是從php端分配的,您可以從php代碼中獲取它,您應該找到javascript在哪里獲取此變量數據,然后可以找到所需的變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM