Lay Theme Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Search

    Extend Lay Theme with standard wordpress API page template?`

    General Discussion
    2
    4
    519
    Loading More Posts
    • 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
      jodldoe last edited by

      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 Reply Quote 0
      • arminunruh
        arminunruh Global Moderator last edited by

        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 Reply Quote 0
        • J
          jodldoe last edited by

          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 Reply Quote 0
          • arminunruh
            arminunruh Global Moderator last edited by arminunruh

            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 Reply Quote 0
            • First post
              Last post
            Post a link to where the problem is if possible, please <3
            I don't answer or check forum DMs, please just post on the forum.
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com

            Before you post:

            Use the Search Feature. Maybe there is already a solution to your issue.

            1. Update Lay Theme and all Lay Theme Addons
            2. Disable all Plugins
            3. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code ", click "Save Changes"
            4. When using a WordPress Cache plugin, disable it or clear your cache. Now see if your problem solved itself.
            Go here, see if your problem is listed here:
            Troubleshooting

            When you post:
            1. Post a link to where the problem is
            2. If the problem is difficult to explain, post screenshots / link to a video to explain it

            Thanks!

            Online Users

            J

            Recent Topics

            • A

              website error

            • Website gone all blank after update 6.3.1

            • S

              can't update project category content

            • C

              lightbox: how to go back to project instead of home with back button

            laytheme.com