Fishpig Magento Integration - php

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.

Related

get language id to Drupal 7 Display suite template

I am trying to add the current node language to the div container of the template file ( I am using Drupal 7 ), here is the current content file I have override:
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
I want it like so:
<div lang='en'>
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
</div>
How can I get the language field where I have only $ds_content variable?
Any help, guide, example or reference appreciated!
You get the current node id through this way.
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
/** get node language **/
$language = node_load($nid)->language;
}
Then pass the language to div
<div lang='<?php print $language; ?>'>
<?php if (isset($title_suffix['contextual_links'])): ?>
<?php print render($title_suffix['contextual_links']); ?>
<?php endif; ?>
<?php print $ds_content; ?>
</div>

PHP echo as condition inside PHP if statement

I would like to use a PHP echo as a condition inside a PHP if statement.
The aim is to have the list of blog articles written by John Doe, displayed on his biography page.
It worked when I directly wrote the author's name in the if condition:
<!-- current page: biography page -->
<div id="list_of_articles_by_John_Doe">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == 'John Doe'): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
But I would like to automate the process, for each writer's biography page to have their own list of articles.
I tried to have as a condition the author of the current biography page ($page):
<!-- current page: biography page -->
<div id="automatic_list_of_articles">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
but it makes another issue: it does not work because inside the foreach statement, $page->author() (condition in the if statement) does not echo the author once, but one time for each page('magazine')->children() as $article.
The condition if($article->author() == $page->author()) does not work in this case, as $page->author() is not strictly the writer's name.
I'm wondering how to call $page->author() to echo the writer's name only once, when inside the foreach statement.
What could be an option is to save all author within an array
// if article->author() isn't within the array
$authors[] == $article->author();
After that you could go as the following:
<?php foreach($authors as $author){ ?>
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
<?php } ?>
That should work, even if you must do 2 foreachs
<?php if( $article->author() == $page->author() ) { ?>
<p><?php echo $article->title(); ?></p>
<?php } ?>
should work, but you can also try
<?php
if( $article->author() == $page->author() ) {
echo "\n<p>", $article->title(), "</p>\n";
}
?>
which to me looks "cleaner"; but you'd have to have a look for missing whitespaces
I suggest trying to set it equal too a variable and then using that variable in the if statement.
<?php foreach(page('magazine')->children() as $article): ?>
<?php $condition = $page->author()?>
<?php if($article->author() == $condition ?>'): ?>
echo "\n<p>", $article->title(), "</p>\n";
<?php endif ?>
<?php endforeach ?>
I am not sure if my syntax is correct but i think it is something along them lines.
You cannot use echo in condition because it is special language construct that sends given contents to the output stream and it returns no value.
Are you sure you shouldn't have this?
<div id="automatic_list_of_articles">
<?php $page = page('magazine'); ?>
<?php foreach($page->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
I have reconstructed an approximation of what looks to be your data, and you can see it working at the link below. It correctly echo's multiple article titles.
Working example:
http://ideone.com/jvLVhF
In this example you can see the PHP as above works correctly, and it is likely a data issue (ie. you should perhaps be using $page and not calling a function in the foreach statement).

Fishpig Wordpress Repeater Fields

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.

Pulling Default WordPress Category Name in Widget

I am trying to add the default category name on my site to a WordPress widget. Is there a way to pull this string (not the ID) automatically? I only have one category so i thought it would be easy, but none of the following are working:
<?php bloginfo('category'); ?>
<?php get_category(); ?>
<?php get_the_category(); ?>
<?php get_category([0]); ?>
<?php get_the_category([0]); ?>
<?php get_category([0]->cat_name); ?>
<?php get_the_category([0]->cat_name); ?>
<?php echo get_category(); ?>
<?php echo get_the_category(); ?>
<?php echo get_category([0]); ?>
<?php echo get_the_category([0]); ?>
<?php echo get_category([0]->cat_name); ?>
<?php echo get_the_category([0]->cat_name); ?>
Any help is appreciated...
UPDATE: 08/01/13 - Amal pushed me onto the right path. I ended up using the following and it worked perfectly...
<?php echo get_cat_name(get_option('default_category'));?>
Try this:
$category = get_category(get_option('default_category'));

How to use checkbox with wpalchemy

I have used following code to create a checkbox in WordPress pages (in admin section):
<?php while($mb->have_fields_and_multi('sidebar-block')): ?>
<?php $mb->the_group_open(); ?>
<!-- Some more code here for other fields -->
<p class="checkbox">
<input name="<?php $metabox->the_name('blue-block'); ?>" type="checkbox" value="1" <?php if ($metabox->get_the_value('blue-block')) echo ' checked="checked"'; ?>>
<label>Do not use Blue Block for content</label>
</p>
<?php $mb->the_group_close(); ?>
<?php endwhile; ?>
Above code is working fine. My question is how can i check if this checkbox is checked on the main website (frontend)?
Following is the code in my template for frontend:
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div id="aside-blue">
<?php if ($sidebar['side_heading']) { ?>
<h2 class="sideheading"><?php echo $sidebar['side_heading']; ?></h2>
<?php } ?>
<?php echo apply_filters( 'the_content', $sidebar['side_content'] ); ?>
</div>
<?php } ?>
<?php } ?>
I want to add id="aside-blue" only when checkbox is checked.
i tried following code for this, but it's not working
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div <?php if ($sidebar['blue-block'] == 'yes') { ?>id="aside-blue"<?php } ?>>
</div>
<?php } ?>
<?php } ?>
Check in the wp_postmeta table how the value is stored. When I used checkboxes, the values were serialized. You'll probably need to unserialize it before using the meta value.

Categories