Wordpress Integration

This is a general guide to integrate the gallery into your Wordpress site. Since the gallery is a client side Javascript application, it won’t need any extra server side code to set it up properly. Only the path to each item asset are dynamic and the gallery needs correct references to those paths to retrieve the assets properly.

Step 1

  • Copy “examples” folder in download package to “wp-content/uploads” folder

  • Rename “examples” to “pr3d”

wp-content
 └── uploads
     └── pr3d
         ├── assets
         ├── css
         ├── js
         └── ...

Step 2

  • We’ll use the Wordpress function “wp_upload_dir()” to retrieve the url of “uploads” dir and add the required scripts and styles.

  • Edit “functions.php” in current themes files located in “wp-content/themes/{selected_themes}” and add these code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 /**
  * Register and enqueue styles.
  */
 function pr3d_styles() {

   $uploads = wp_upload_dir();
   wp_enqueue_style( 'opensans', "https://fonts.googleapis.com/css?family=Open+Sans:300,400");
   wp_enqueue_style( 'roboto', "https://fonts.googleapis.com/css?family=Roboto:300i&display=swap");
   wp_enqueue_style( 'videojs', "https://vjs.zencdn.net/7.6.6/video-js.css");
   wp_enqueue_style( 'pr3d', $uploads['baseurl'] . '/pr3d/css/pr3d.min.css');

   $custom_css = "

     // Add inline custom styles
     .rs-container {
       /*background:#eee;*/
     }
   ";
   wp_add_inline_style('pr3d', $custom_css);
 }
 add_action( 'wp_enqueue_scripts', 'pr3d_styles' );

 /**
  * Register and enqueue scripts.
  */
 function pr3d_scripts() {

   $uploads = wp_upload_dir();
   wp_enqueue_script( 'videojs', "https://vjs.zencdn.net/7.6.6/video.min.js");
   wp_enqueue_script( 'anime', 'https://cdn.jsdelivr.net/npm/[email protected]/lib/anime.min.js');
   wp_enqueue_script( 'pr3d', $uploads['baseurl'] . '/pr3d/js/pr3d.min.js');
 }
 add_action( 'wp_enqueue_scripts', 'pr3d_scripts' );

Step 3

  • If the gallery resides in a singe post, copy “single.php” and rename it to “pr3d.php”

  • If the gallery resides in a singe page, copy “page.php” and rename it to “pr3d.php”

  • Add custom template name in the beginning of “pr3d.php”:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 <?php

 /**
  * Custom page template for PhotoRow
  * Template Name: pr3d
  * Template Post Type: post, page
  */

 get_header();
 ?>

Step 4

  • Retrieve the upload folder url then insert the gallery setup code into “pr3d.php”:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 <?php
 /**
  * Custom page template for PhotoRow
  * Template Name: pr3d
  * Template Post Type: post, page
  */

 get_header();
 ?>
 <main id="site-content" role="main">

   <?php
     $baseurl = wp_upload_dir()['baseurl'] . "/pr3d";
   ?>
       <div class="rs-container">
         <div class="rs-pr3d">
           <ul data-name="Art Gallery">
             <li> <a href="<?=$baseurl?>/assets/art/1.jpg" title="Item 1" data-extended="<?=$baseurl?>/assets/art/extended/1.jpg" data-type="photo" data-thumbnail="<?=$baseurl?>/assets/art/thumbs/1.jpg">Item 1</a>
                 <p>"It is not a lack of love, but a lack of friendship that makes unhappy marriages." – <em>Friedrich Nietzsche</em></p>
               </li>
               <li> <a href="<?=$baseurl?>/assets/art/2.jpg" title="Item 2" data-extended="<?=$baseurl?>/assets/art/extended/2.jpg" data-type="photo" data-thumbnail="<?=$baseurl?>/assets/art/thumbs/2.jpg">Item 2</a>
                 <p>"The secret of getting ahead is getting started. " - <em>Mark Twain</em></p>
               </li>
           </ul>
         </div>
       </div>
   <?php

   if ( have_posts() ) {
     while ( have_posts() ) {
       the_post();
       get_template_part( 'template-parts/content', get_post_type() );
     }
   }

   ?>

 </main><!-- #site-content -->

 <script type="text/javascript">

   document.body.onload = function() {

     var el = document.querySelector('.rs-pr3d');
     var pr3d = new PhotoRow(el, {
       useMouseDrag:true,
       components:[0, 1, 2],
       itemDistance:400,
       shearAngle:45,
       roundCorner:10,
       viewAngleX:20,
       easing:'easeOutQuint',
       duration:1000,
       categoryMenu:{
         horizontal:true
       }
     });
     window.pr3d = pr3d;
   }
 </script>

 <?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>
 <?php get_footer(); ?>

Step 5

  • In the Wordpress admin page, edit or create a new post/page. Select “pr3d” as the custom template for the post/page attribute.