So I've got a Magento install, with Fishpig Wordpress Integration and the ACF plugin to pull in meta values. I'm also using the repeater field here which pulls in the metadata as an array (as I understand it). The Fishpig documentation is non- existent so alot of this is guess work really but here's my code:
<?php
/**
* #category Fishpig
* #package Fishpig_Wordpress
* #license http://fishpig.co.uk/license.txt
* #author Ben Tideswell <help#fishpig.co.uk>
*/
?>
<?php $page = $this->getPage() ?>
<?php if ($page): ?>
<?php $helper = $this->helper('wordpress') ?>
<?php $author = $page->getAuthor() ?>
<div class="page-title">
<h1><?php echo $this->escapeHtml($page->getPostTitle()); ?></h1>
</div>
<?php
$lookbooks = $page->getMetaValue('lookbooks');
if($lookbooks):
foreach ($lookbooks as $lookbook) {
$title = $lookbook['title'];
$content = $lookbook['content'];
$images = array($lookbook['images']);?>
<h2><?php echo $title;?></h2>
<div class="connected-carousels">
<div class="stage">
<ul>
<?php foreach($images as $image) { ?>
<li>
<img src="<?php echo $image['image'];?>" alt="<?php echo $image['alt'];?>" />
</li>
<?php } ?>
</ul>
‹
<a href="#" class="next next-stage" >›</a>
</div>
<div class="navigation">
‹
<a href="#" class="next next-navigation" >›</a>
<div class="carousel carousel-navigation">
</div>
</div>
</div>
<?php echo $content ; ?>
<?php }
else : ?>
<div class="post-view">
<div class="entry std">
<?php if ($page->isViewableForVisitor()): ?>
<?php if ($featuredImage = $page->getFeaturedImage()): ?>
<div class="featured-image left"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt=""/></div>
<?php endif; ?>
<?php echo $page->getPostContent() ?>
<br style="clear:both;"/>
<?php else: ?>
<?php echo $this->getPasswordProtectHtml() ?>
<?php endif; ?>
</div>
</div>
<?php endif;?>
<?php endif; ?>
What I'm trying to do is use the repeater field to make a carousel using jcarousel, I'm fine with my jquery but there's some sort of PHP error here preventing the page from loading.
Here's my ACF structure with the labels:
lookbook (repeater)
--title
--content
--images (repeater)
----image
----alt
I can't see any php errors in the servers error log, nor is the page displaying any errors. It's just not echoing the $image array although it is repeating the loop the right amount of times.
Maybe I'm miles away, maybe I'm nearly there I just can't see anything wrong with it.
Thanks in advance
There is an issue in version 1.2.1.0 of the ACF extension that breaks repeater fields that are embedded inside a repeater field. I have just released version 1.2.2.0 that fixes this issue and allows you to use repeater fields inside other repeater fields.
Related
I am working with Heroic Knowledge Base, and I am having trouble getting only one breadcrumb to show up (their suggested CSS code is not working). Unfortunately, I am not a PHP expert, and I am not sure how to edit the code so that it only shows one of the lines that it is pulling (we don't care which one) I have added the PHP from their breadcrumbs file. Any assistance would be greatly appreciated.
<?php
/**
* Breadcrumbs template
*/
?>
<?php if(hkb_show_knowledgebase_breadcrumbs()): ?>
<!-- .hkb-breadcrumbs -->
<?php $breadcrumbs_paths = ht_kb_get_ancestors(); ?>
<?php foreach ($breadcrumbs_paths as $index => $paths): ?>
<ol class="hkb-breadcrumbs" itemscope
itemtype="http://schema.org/BreadcrumbList">
<?php $last_item_index = count($paths)-1; ?>
<?php foreach ($paths as $key => $component): ?>
<li itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">
<?php if($key==$last_item_index): ?>
<span itemprop="item">
<span itemprop="name"><?php echo
$component['label']; ?></span>
</span>
<?php else: ?>
<a itemprop="item" href="<?php echo $component['link']; ?>">
<span itemprop="name"><?php echo $component['label']; ?></span>
</a>
<?php endif; ?>
<meta itemprop="position" content="<?php echo $key+1; ?>" />
</li>
<?php endforeach; ?>
</ol>
<?php endforeach; ?>
I was able to solve this issue using the following code, however I would like to make it so that it is only effective when there is more than one.. the code below worked on articles with two breadcrumbs, but when there is only one it hid them all together.
ol.hkb-breadcrumbs {
display: table-column-group;
}
Apologies, I am relatively new to PHP and am learning as I go, but am stuck on this... I have this template for a page-title section with a background image. I can add the background image, but if there is no background-img:url elected on the page, is there a way to write in a default background-img:url into this template?
<section class="page-title" <?php if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>');"<?php endif;?>>
<div class="auto-container">
<h1><?php if($title) echo balanceTags($title); else wp_title('');?></h1>
<div class="bread-crumb">
<?php echo convo_get_the_breadcrumb();?>
</div>
</div>
Add this before your code:
if(empty($bg)){
$bg = '/path/to/your/default/image.jpg';
}
<section class="page-title" <?php if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>')" <?php else: ?>
style="background-image:url('your URL')"
<?php endif; ?>>
Using #psdev's code, I was able to add in a default background-image if $bg was empty. Thanks!!
<section class="page-title" <?php if(empty($bg)){$bg = 'http://aqmenalt.mhsites.co.uk/wp-content/uploads/2017/06/Banner-10.png';} if($bg):?>style="background-image:url('<?php echo esc_url($bg);?>');"<?php endif;?>>
<div class="auto-container">
<h1><?php if($title) echo balanceTags($title); else wp_title('');?></h1>
<div class="bread-crumb">
<?php echo convo_get_the_breadcrumb();?>
</div>
</div>
Because I am not a professional programmer, I can’t get the ACF integration up for the fishpig magento running.
Bought both the FishPig-ACF Add-on and the ACF Pro.
Installed both and made a custom field named “repeater” and as the autor describes in his manual, I added this code to the /post/view.phtml:
<?php $value = $post->getMetaValue('repeater') ?>
So my view.phtml looks like this:
<?php
/**
* #category Fishpig
* #package Fishpig_Wordpress
* #license http://fishpig.co.uk/license.txt
* #author Ben Tideswell <help#fishpig.co.uk>
*/
?>
<?php $post = $this->getPost() ?>
<?php if ($post): ?>
<?php $helper = $this->helper('wordpress') ?>
<?php $author = $post->getAuthor() ?>
<div class="page-title post-title">
<h1><?php echo $this->escapeHtml($post->getPostTitle()) ?></h1>
</div>
<div class="post-view">
<p class="post-date when"><?php echo stripslashes($this->__('This entry was posted on %s<span class=\"by-author\"> by %s</span>.', $post->getPostDate(), $post->getAuthor()->getDisplayName())) ?></p>
<?php echo $this->getBeforePostContentHtml() ?>
<?php $value = $post->getMetaValue('repeater') ?>
<div class="post-entry entry std<?php if ($post->getFeaturedImage()): ?> post-entry-with-image<?php endif; ?>">
<?php if ($post->isViewableForVisitor()): ?>
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
<div class="featured-image left"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/></div>
<?php endif; ?>
<?php echo $post->getPostContent() ?>
<?php else: ?>
<?php echo $this->getPasswordProtectHtml() ?>
<?php endif; ?>
</div>
<?php echo $this->getAfterPostContentHtml() ?>
<?php echo $this->getCommentsHtml() ?>
</div>
<?php endif; ?>
But in fronted the ACF is not shown.
THX for any help
You have copied and pasted the following code:
<?php $value = $post->getMetaValue('repeater') ?>
This code generates the repeater value and saves it in a variable named $value. That's it. This code doesn't do anything with this value or print it to the screen so the fact that nothing is displayed is correct.
To view what's inside the field, try the following:
<pre><?php print_r($post->getMetaValue('repeater')) ?></pre>
The above code will print out the value of the repeater field to the screen. Assuming you have set a value for this field for the current post, this value be an array containing the data that you set. You will then need to make use of foreach loops to cycle through the array and process/display the data.
I am currently using a Wordpress plugin called Facebook Page Album and below is the example code for showing the Facebook page albums list and I'm trying to convert it into Wordpress short code but I'm not sure how I should go about it as I'm not to familiar with Wordpress but I can only seem to use the Return statement so how would I go about using the following code with a short code.
<?php
$list = facebook_page_albums_get_album_list();
?>
<ol class="album-list">
<?php foreach ($list as $item) : ?>
<?php
if ($item['type'] != 'normal' || $item['name'] == 'Cover Photos') continue;
?>
<li class="album">
<?php if ($thumb = $item['cover_photo_data']):?>
<div class="album-thumb">
<a href="<?php echo add_query_arg('id', $item['id']);?>">
<img src="<?php echo $thumb['picture'];?>"/>
</a>
</div>
<?php endif; ?>
<div class="album-info">
<h5><?php echo $item['name'];?></h5>
<div class="counts">
<div class="photos-count"><?php echo $item['count'];?></div>
<?php if (!empty($thumb['comments'])) :?><div class="comments-count"><?php echo count($thumb['comments']['data']);?></div><?php endif;?>
<?php if (!empty($thumb['likes'])) :?><div class="likes-count"><?php echo count($thumb['likes']['data']);?></div><?php endif;?>
</div>
</div>
</li>
<?php endforeach;?>
</ol>
I am attempting to make a sortable list out of list items populated from the database using the jQuery plug in but the effect is only applied to the first item presented:
<?php if(isset($bookmarks)) : foreach($bookmarks as $row) :?>
<div id="makeDrag">
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small">
<?php echo anchor("site/delete/$row->id", "Delete"); ?>
</h4>
</li>
</div>
<?php endforeach; ?>
I can kind of see where this is going wrong but do not know how to fix it. I would obviously like the effect to affect all the populated li not just the first one. Any help would be great. Sorry if I am unclear, I can try and rephrase things if this is confusing.
The cause is likely because you have
$('#makeDrag').sortable();
but you also have a foreach statement that creates multiple #makeDrag elements thus making your HTML invalid.
To fix this:
<?php if(isset($bookmarks)) : ?>
<ul id="makeDrag">
<?php foreach($bookmarks as $row) : ?>
<?php $fixed = preg_replace('#^[^:/.]*[:/]+#i', '', $row->URL); ?>
<li>
<div class="well">
<div><?php echo anchor('http://'.$fixed, $row->Name); ?></div>
<div><strong>Comments:</strong> <?php echo $row->Comments; ?></div>
<h4 class="btn-small"><?php echo anchor("site/delete/$row->id", "Delete"); ?></h4>
</div>
</li>
<? endforeach; ?>
</ul>
<?php endif; ?>
HTH