Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • 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 898 Views 2 Watching
  • 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
    J
    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
      arminunruhA
      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
        J
        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
          arminunruhA
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          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