最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to transfer variables from one function to another

programmeradmin0浏览0评论
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I want to transfer $linker_sluger from function which create page to function which create gallery, but when i make it as global and try transfer it, it's clear.

function page_creator(){
global $wpdb, $ling, $slugerr, $linker_sluger, $tester;
$linker_sluger= $ling.'/'.$slugerr;

$poster_id = $wpdb ->get_results("SELECT ID from wp_posts WHERE post_status='publish' AND post_type='post' ORDER BY ID DESC");

foreach ($poster_id as $posters_id){

    global $post;
    $post = get_post($posters_id->ID);

    $galleries_counter = get_post_galleries($post, false );
    $total_gal = count( $galleries_counter );

    $ile_fotek = _get_total_images($galleries_counter );


    if(has_shortcode( $post->post_content, 'gallery' ) && $ile_fotek<1){
        echo"za malo fotek mniej niz ".$ile_fotek;
    }
    elseif(has_shortcode( $post->post_content, 'gallery' )){
        echo "FOTKIbb: ".$ile_fotek;
        if (is_page(376)){
            echo'<div class="single-album col-md-3 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID); 
            echo '</div>';
            $galeryjka =  na_get_gallery_image_urls($posters_id->ID);

            $title = get_the_title($post);
            $Poster = new PostController;
            $Poster->set_title($title);
            //$Poster->add_category(array(1,2,8));
            $Poster->set_type("page");
            $Poster->set_content("[insert_php]na_get_gallery_image_urls($posters_id->ID);[/insert_php]" );
            $Poster->set_author_id( 1 );
            $Poster->set_post_slug("galeria-".$title);
            $sluger = $Poster->set_post_slug("albums-inside-".$title);
            $Poster->set_page_template( "page-single-gallery.php" );
            $Poster->set_post_state( "publish" );
            $Poster->search('title', 'Old Post');
            $Poster->update();
            $Poster->create();
            //$Poster->PrettyPrintAll();
            $Poster->get_var('slug');
            $ling = get_home_url();
            $slugerr = sanitize_title($sluger, '', 'save');
            $linker_sluger = $ling.'/'.$slugerr;   // transfer this $linker_sluger to bottom function, but when try it clear




        }
        else{
            echo'<div class="col-md-12 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID);
            echo '</div>';
        }




    }




 }
}


function na_get_gallery_image_urls( $post_id ) {
global $wpdb, $linker_sluger, $ling, $slugerr, $tester;
$post = get_post($post_id);


// Make sure the post has a gallery in it
if( ! has_shortcode( $post->post_content, 'gallery' ) )
    return;



// Retrieve all galleries of this post
$galleries = get_post_galleries_images( $post );
$title = get_the_title($post_id);

//$poster_guid = $wpdb->get_results("SELECT guid from wp_posts WHERE post_name LIKE ('albums-inside-%') ORDER BY guid DESC");
echo '<h3>'. $title .'</h3>'; 


// Loop through all galleries found
foreach( $galleries as $gallery ) {
    // Loop through each image in each gallery
        foreach( $gallery as $image) {

            if(is_page( 376 )){
                echo '<div class="single-image page-gallery col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';

            }

            elseif(is_page( 5 )){
                echo '<div class="single-image page-home col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';

            }

            else{
                echo '<div class="single-image page-inside-gallery col-md-3 col-sm-12">';
                echo '<a class="foobox" rel="gallery" href="'.$image.'"><img src="'.$image.'"></a>';
                echo '</div>';  


                }
        }
    }   
}
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I want to transfer $linker_sluger from function which create page to function which create gallery, but when i make it as global and try transfer it, it's clear.

function page_creator(){
global $wpdb, $ling, $slugerr, $linker_sluger, $tester;
$linker_sluger= $ling.'/'.$slugerr;

$poster_id = $wpdb ->get_results("SELECT ID from wp_posts WHERE post_status='publish' AND post_type='post' ORDER BY ID DESC");

foreach ($poster_id as $posters_id){

    global $post;
    $post = get_post($posters_id->ID);

    $galleries_counter = get_post_galleries($post, false );
    $total_gal = count( $galleries_counter );

    $ile_fotek = _get_total_images($galleries_counter );


    if(has_shortcode( $post->post_content, 'gallery' ) && $ile_fotek<1){
        echo"za malo fotek mniej niz ".$ile_fotek;
    }
    elseif(has_shortcode( $post->post_content, 'gallery' )){
        echo "FOTKIbb: ".$ile_fotek;
        if (is_page(376)){
            echo'<div class="single-album col-md-3 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID); 
            echo '</div>';
            $galeryjka =  na_get_gallery_image_urls($posters_id->ID);

            $title = get_the_title($post);
            $Poster = new PostController;
            $Poster->set_title($title);
            //$Poster->add_category(array(1,2,8));
            $Poster->set_type("page");
            $Poster->set_content("[insert_php]na_get_gallery_image_urls($posters_id->ID);[/insert_php]" );
            $Poster->set_author_id( 1 );
            $Poster->set_post_slug("galeria-".$title);
            $sluger = $Poster->set_post_slug("albums-inside-".$title);
            $Poster->set_page_template( "page-single-gallery.php" );
            $Poster->set_post_state( "publish" );
            $Poster->search('title', 'Old Post');
            $Poster->update();
            $Poster->create();
            //$Poster->PrettyPrintAll();
            $Poster->get_var('slug');
            $ling = get_home_url();
            $slugerr = sanitize_title($sluger, '', 'save');
            $linker_sluger = $ling.'/'.$slugerr;   // transfer this $linker_sluger to bottom function, but when try it clear




        }
        else{
            echo'<div class="col-md-12 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID);
            echo '</div>';
        }




    }




 }
}


function na_get_gallery_image_urls( $post_id ) {
global $wpdb, $linker_sluger, $ling, $slugerr, $tester;
$post = get_post($post_id);


// Make sure the post has a gallery in it
if( ! has_shortcode( $post->post_content, 'gallery' ) )
    return;



// Retrieve all galleries of this post
$galleries = get_post_galleries_images( $post );
$title = get_the_title($post_id);

//$poster_guid = $wpdb->get_results("SELECT guid from wp_posts WHERE post_name LIKE ('albums-inside-%') ORDER BY guid DESC");
echo '<h3>'. $title .'</h3>'; 


// Loop through all galleries found
foreach( $galleries as $gallery ) {
    // Loop through each image in each gallery
        foreach( $gallery as $image) {

            if(is_page( 376 )){
                echo '<div class="single-image page-gallery col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';

            }

            elseif(is_page( 5 )){
                echo '<div class="single-image page-home col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';

            }

            else{
                echo '<div class="single-image page-inside-gallery col-md-3 col-sm-12">';
                echo '<a class="foobox" rel="gallery" href="'.$image.'"><img src="'.$image.'"></a>';
                echo '</div>';  


                }
        }
    }   
}
Share Improve this question edited Aug 7, 2019 at 12:17 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Aug 7, 2019 at 10:24 nctincti 135 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Whatever happens in your function (I didn't look deep in it) you can pass more then one parameter if you call the function

na_get_gallery_image_urls($posters_id->ID, $linker_sluger);

and use the value.
But makes it sense? Once you put an echo in a variable $galeryjka and then you echo the echo?

发布评论

评论列表(0)

  1. 暂无评论