Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Extend Lay Theme with standard wordpress API page template?`

Extend Lay Theme with standard wordpress API page template?`

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 637 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jodldoe
    wrote on last edited by
    #1

    Hey! Loving the theme, great work.

    I was wondering – is there a best practice to extend the theme with a page template that just displays data directly via the Wordpress PHP API, like a page-{id}.php that wp_queries all titles and links from a particular category?

    I was looking through the LAY template files and got a bit confused at <%= showContent() %> – how can I insert data from a wp_query call in the Lay gridder layout in a template file?

    Thanks!

    1 Reply Last reply
    0
    • arminunruhA Offline
      arminunruhA Offline
      arminunruh
      Global Moderator
      wrote on last edited by
      #2

      Hey jodldoe!
      Hm no that doesn't work with Lay Theme. Lay Theme's frontend is a javascript application. So it doesn't use any php files like page-{id}.php :/

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jodldoe
        wrote on last edited by
        #3

        Thanks Armin! Where there is will, there is a way :) Passing html code generated through PHP in the main template file through a simple variable in showContent(string) somehow permits me to do what I needed (show an index of projects on a page), but of course it won't survive the next update. Lets see if theres a better way.

        1 Reply Last reply
        0
        • arminunruhA Offline
          arminunruhA Offline
          arminunruh
          Global Moderator
          wrote on last edited by arminunruh
          #4

          Ok, I see

          http://laytheme.com/documentation.html#custom-javascript
          You could also fetch your data using wp-api. http://v2.wp-api.org/
          That's what lay theme uses.

          In this case it's pretty slow, cause first I fetch all posts, then I fetch each featured image (project thumbnails) and that just takes long. :/

          <script>
          Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj){
          	if(type == "page" && obj.id == 20){
          		//fetch projects
          		jQuery.getJSON(frontendPassedData.wpapiroot+'wp/v2/posts/', function(result){
          			console.log(result);
          			for(var i=0; i<result.length; i++){
          				var fi_id = result[i].featured_image;
          				jQuery.getJSON(frontendPassedData.wpapiroot+'wp/v2/media/'+fi_id, function(result){
          					console.log(result);
          				});
          			}
          		});
          	}
          });
          </script>
          

          But maybe you don't need all the featured images but just the project titles. That's faster:

          <script>
          Frontend.GlobalEvents.on("newpageshown", function(layoutObj, type, obj){
          	if(type == "page" && obj.id == 20){
          		//fetch projects
          		jQuery.getJSON(frontendPassedData.wpapiroot+'wp/v2/posts/', function(result){
          			for(var i=0; i<result.length; i++){
          				console.log(result[i].title.rendered);
          			}
          		});
          	}
          });
          </script>
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          💿 Email me here: 💿
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

          This often solves issues you might run into

          When you post:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search