In a template, I want to clone the content of "#content-standard" into #content-blue. That is done in jQuery and works fine. The cloned content gets different styling, which is set in its new parent with class "new-bgcolor".
HTML
<div class="content-wrapper">
<div class="content-container-main">
<div id="content-blue" class="new-bgcolor">
</div>
</div>
<div id="content-standard">
<main id="front-page" role="main">
<?php $args = array('posts_per_page'=>1,'cat=-2');
if(!isset($loopfront)){ $loopfront='';} $loopfront = new WP_Query($args);
while ( $loopfront->have_posts() ) { $loopfront->the_post(); get_template_part( './parts/content', 'page' );}unset($loopfront); ?>
</main>
</div>
But after cloning, I need to replace a certain piece of this content to match with the new styling from new-bgcolor.
The content from content-standard get generated by fetching the theme part content-page.php in the folder parts. For content-standard inside the div content-blue, I need to load another template part, which loads a function. What this function does is cloning and altering an uploaded image with an iMagick script and extends the name so the changed image doen't overwrite the original.
So template part "content-page.php" with #content-standard" loads an image "//localhost:3000/content/uploads/2017/09/image.jpg", template part "content-page_blue.php" should load "//localhost:3000/content/uploads/2017/09/image-blurred.jpg"
content-page_blue.php gets the blurred image by this function.
<?php $page = get_post(); $image_alt = get_post_meta( $page->ID, '_wp_attachment_image_alt', true); $featured = wp_get_attachment_image( get_post_thumbnail_id($page->ID), 'full' ); $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true); $path = pathinfo($thumb_url[0]); $extension = pathinfo($thumb_url[0], PATHINFO_EXTENSION); $newfilename = $path['filename']."-blurred"; $newfile = $path['dirname']."/".$newfilename.".".$extension; $thumbs = get_field('thumbs', $page->ID);?><?php if($featured) { ?> <div id="post-featured-<?php echo $post->ID; ?>" class="post-image"><a href="<?php the_permalink(); ?>"><img src="<?php echo $newfile; ?>"/></a><p><?php echo get_post(get_post_thumbnail_id())->post_excerpt;?></p></div><?php } ?>
This is also tested and works fine in a previous setup. The problem with the new setup is that I can't seem to load "content-page_blue.php" in the cloned div. My knowledge of jQuery is limited and I used this:
$("#content-standard").clone().appendTo("#content-blue"); var newContent = $('#content-blue').siblings('#content-standard'); $('#content-blue').load("parts/content-page_blue.php" + newContent);
It can't find the template part and bounced an
Maybe this has got to do with the WP Skeleton setup (which puts the content and WP folder in a public folder) in combination of the page that loads the script is different from the template parts? It looks like this: theme setup. Any help is appreciated and sorry for the long story.
newContentis a jQuery object, why are you concatenating it in the load function ? - adeneoloadyou can fetch content from an element inside the loaded page, but you have to pass a string, like.load("mypage.php #elem"), right now you're passing in an jQuery object, and end up with the same as.load("mypage.php[object, Object]")- adeneo