WordPress.org

Ready to get started?Download WordPress

Forums

Loading all content for zero load time !Help! (4 posts)

  1. BillyAtStudioPretty
    Member
    Posted 1 year ago #

    Hi,

    A client has picked up on the minute time between pages where the screen goes white and quite rightly pointed out "we only need to load (the content), (the title), and (the featured image) each time.. can't we do this and keep the rest displayed?"

    The only way I can think of doing this is by loading all of the content in the header using get_pages(); and storing it in an array, with the pages ID as the key, then use javascript to display and remove content.

    I would use a custom walker to remove the href from nav menus and instead have a function onClick like changePage($id) or something.

    has anyone ever done anything like this before, and can you offer any advice on how I should go about it?
    would you say I shouldn't do this?

    the site is located on our staging site at http://anticom.tv/fmegroup

  2. BillyAtStudioPretty
    Member
    Posted 1 year ago #

    can anyone help me? I have encountered my first problem after attempting this, which is trying to get the array returned by get_pages into java script in order to utilize the content that i need.

    I also realized that the page templates that I made for the theme have been rendered a bit redundant as I will be using JS to add/remove/change content. sigh.

    anyway, I came up with this code, but the page refuses to load and I don't know why.

    <script type="text/javascript">
    	$(document).ready(function(){
    
    		pages = new Array();
    
    		<?php
    		$pages = get_pages();
    		foreach ($pages as $page): ?>
    
    			pages[<? echo $page->ID; ?>] = <? echo $page; ?>;
    
    		<? endforeach; ?>
    
    	});
    	</script>
  3. BillyAtStudioPretty
    Member
    Posted 1 year ago #

    in the foreach loop, I changed the <? echo $page ?> to echo_r, which allows the page to load, but gives and error because I'm trying to use a std class object in an array. (I think?)

    does anyone have a good way to get $pages (an array of objects) into js as an array of arrays?

  4. BillyAtStudioPretty
    Member
    Posted 1 year ago #

    can someone PLEASE help?

Topic Closed

This topic has been closed to new replies.

About this Topic