Untitled
raw download clone
TEXT
views 59
,
size 5789 b
function page_creator()
    {
        //global $wpdb;
        global $post;
        global $linker_sluger;
        $query = new WP_Query(array('post_type' => 'post'));
        $posts = $query->posts;
        foreach ($posts as $key => $post) {
            $post_id = get_post($post->ID);
            $post_name = get_post($post->ID);
            $image_id = get_field('dodaj_galerie', $post_id->ID);


            $images_string = implode(',', $image_id);
            $shortcode = sprintf('[custom_gallery ids="%s"]', $images_string);


            print_r($post_id->ID . ' ' . $post_name->post_name . ' ' . $images_string);

            if ($image_id) {
                echo " true</br>";


                $title = get_the_title($post->ID);
                $Poster = new PostController;
                $Poster->set_title($title.'-'.$post->ID);
                //$Poster->add_category(array(1,2,8));
                $Poster->set_type("page");
                $Poster->set_content($shortcode);
                $Poster->set_author_id( 1 );
                $Poster->set_post_slug("album");
                //$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');

                $sluger=$title.'-'.$post->ID;
                $slugerr = sanitize_title($sluger, '', 'save');
                $linker_sluger = get_home_url().'/'.$slugerr;   // transfer this sluger to bottom function
                echo $linker_sluger .' DOBRY LINK';





            } else {
                echo "false";
            }

        }
    }




    add_shortcode('custom_gallery', 'custom_gallery_fn');
    function custom_gallery_fn($attr)
    {
        global $post;

        if (isset($attr['orderby'])) {
            $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
            if (!$attr['orderby'])
                unset($attr['orderby']);
        }

        extract(shortcode_atts(array(
            'order' => 'DESC',
            'orderby' => 'menu_order ID',
            'id' => $post->ID,
            'itemtag' => 'dl',
            'icontag' => 'dt',
            'captiontag' => 'dd',
            'columns' => 3,
            'size' => 'large',
            'ids' => '',
            'exclude' => ''
        ), $attr));

        $id = intval($id);
        if ('RAND' == $order) $orderby = 'none';

        if (!empty($ids)) {
            $ids = preg_replace('/[^0-9,]+/', '', $ids);
            $_attachments = get_posts(array(
                    'include' => $ids,
                    'post_status' => 'inherit',
                    'post_type' => 'attachment',
                    'post_mime_type' => 'image',
                    'order' => $order,
                    'orderby' => $orderby
                )
            );

            $attachments = array();
            foreach ($_attachments as $key => $val) {
                $attachments[$val->ID] = $_attachments[$key];
            }
        }

        if (empty($attachments)) return '';

        if (is_page(16)) {
            // Here's your actual output, you may customize it to your need
            $output = '<div class="single-album col-md-6 col-12">';


            // Now you loop through each attachment
            foreach ($attachments as $id => $attachment) {
                // Fetch the thumbnail (or full image, it's up to you)
                // $img = wp_get_attachment_image_src($id, 'medium');
                // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
                $img = wp_get_attachment_image_src($id, 'full');
                $output .= "<a href=\"\" class=\"foobox col-md-12 col-12\" rel=\"gallery\">";
                $output .= "<div class=\"single-gallery-image\">";
                $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
                $output .= "<div class=\"title-album\">";
                $output .= "<p>" . get_the_title() . "</p> ";
                $output .= "<p>Zobacz pełną galerię</p> ";
                $output .= "</div>";
                $output .= "</div>";
                $output .= "</a>";
            }
            //$output .= "</div>\n";

            $output .= "</div>";

        } else {
            // Here's your actual output, you may customize it to your need
            $output = '<div class="gallery-investition-single col-md-12 col-12">
                    <div class="row">';


            // Now you loop through each attachment
            foreach ($attachments as $id => $attachment) {
                // Fetch the thumbnail (or full image, it's up to you)
                // $img = wp_get_attachment_image_src($id, 'medium');
                // $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
                $img = wp_get_attachment_image_src($id, 'full');
                $output .= "<a href=\"{$img[0]}\" class=\"foobox col-md-4 col-12\" rel=\"gallery\">";
                $output .= "<div class=\"single-gallery-image\">";
                $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
                $output .= "</div>";
                $output .= "</a>";
            }
            //$output .= "</div>\n";
            $output .= "</div>";
            $output .= "</div>";
        }


        return $output;
    }
close fullscreen
Login or Register to edit or fork this paste. It's free.