Jump to content

JSON of all pages/specific sections of site as one data set


a-ok
 Share

Recommended Posts

I realise this may be a generic JSON/PHP question but I want to make sure I'm harnessing the API correctly from the beginning.

I want to create a JSON data output of pages of my site, as well as individual pages, but I'm unsure how to do this as one whole output. I know and can output, for example, projects within a project, but how do I also output the homepage content, and other page content, at the same time? 

The JSON output would include things like 'home' and 'project' arrays but would be blank if you aren't viewing the homepage and or project page... if that makes sense.

$projects_array = array(
	'projects' => array()
);

$projects = $pages->find('template=projects-detail, sort=sort');

foreach ($projects as $project) {

    $project_content = array(
        'id' => $project->id,
		'title' => $project->title,
		'name' => $project->name,
		'size' => $project->projects_categories_projects_size,
		'img' => array(
			'featured' => $project->projects_detail_featured_image->url
		)
    );
    array_push($projects_array['projects'], $project_content);

}

$projects_json = json_encode($projects_array, true);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...