Closed. This question needs details or clarity. It is not currently accepting answers.admin管理员组文章数量:1417053
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI 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 questionI 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
1 Answer
Reset to default 0Whatever 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?
本文标签: phpHow to transfer variables from one function to another
版权声明:本文标题:php - How to transfer variables from one function to another 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745262114a2650403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论