i'm making a multilanguage website which uses the advanced custom fields relationship plugin. I'm reading out employers and if i read em out in the site's native language i have zero problems, however when i try to read them out in another language i get back a empty array.
Do any of you guys know what i can do?
<?php
$field = get_post_meta( get_the_id() );
$posts = get_field('field_81');
echo '<!--';
echo 'test ';
var_dump( $field );
var_dump( $posts );
echo '-->';
?>
<?php
if (ICL_LANGUAGE_CODE == 'en'):
?>
<?php
$fields = $field['medewerkers'];
?>
<?php
$posts = $fields;
?>
<?php
endif;
?>
<?php
if ($posts):
?>
<?php
if (ICL_LANGUAGE_CODE == 'nl'):
?>
<h3 class="titelmedewerkers">Medewerkers</h3>
<?php
elseif (ICL_LANGUAGE_CODE == 'en'):
?>
<h3 class="titelmedewerkers">Employees</h3>
<?php
elseif (ICL_LANGUAGE_CODE == 'fr'):
?>
<h3 class="titelmedewerkers">Employes</h3>
<?php
else:
?>
<h3 class="titelmedewerkers">Medewerkers</h3>
<?php
endif;
?>
<ul class="medewerkers">
<?php
foreach ($posts as $post): // variable must be called $post (IMPORTANT)
?>
<?php
setup_postdata($post);
?>
<li class="shadow">
<strong><?php
the_title();
?></strong><br />
<?php
if (get_field('foto')):
?>
<?php
$attachment_id = get_field('foto');
$size = "medium";
$image = wp_get_attachment_image_src($attachment_id, $size);
?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /><br />
<?php
endif;
?>
<?php
if (get_field('afdeling')):
?>
<?php
the_field('afdeling');
?><br />
<?php
endif;
?>
<?php
if (get_field('titel')):
?>
<?php
the_field('titel');
?><br />
<?php
endif;
?>
<?php
if (get_field('tel')):
?>
<?php the_field('tel'); ?><br />
<?php
endif;
?>
</li>
<?php
endforeach;
?>
<?php
wp_reset_postdata();
?>
</ul>
<?php
endif;
?>
<?php
wp_reset_postdata();
?>
this part:
<?php
if (ICL_LANGUAGE_CODE == 'en'):
?>
<?php
$fields = $field['medewerkers'];
?>
<?php
$posts = $fields;
?>
<?php
endif;
?>
creates $post only when en, not surprising that you don't have it in other languages
Related
This is the selector script I believe below so what should happen is as you select a product then you select if its your an individual or couple or family then you click show me and it takes you to the correct link
<div class="finder__selector">
<?php /* Set first option as the default option */ ?>
<?php $count = 1; while ( have_rows('links') ) : the_row(); ?>
<?php $link_url = get_sub_field('link_url'); ?>
<?php if($product_name): ?>
<?php //echo $product_name; ?>
<?php //echo $link_url; ?>
<?php if(strpos($link_url, $product_name) !== false): ?>
<?php the_sub_field('link_title'); ?><i class="down-arrow"></i>
<?php endif; ?>
<?php else: ?>
<?php if($count == 1) : ?>
<?php the_sub_field('link_title'); ?><i class="down-arrow"></i>
<?php endif; ?>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
<div class="finder__options">
<?php $count = 1; ?>
<?php while ( have_rows('links') ) : the_row(); ?>
<?php $link_url_select = get_sub_field('link_url'); ?>
<?php $link_title_select = get_sub_field('link_title'); ?>
<?php if($product_name): ?>
<?php if(strpos($link_url_select, $product_name) !== false): ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php else: ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php endif; ?>
<?php else: ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
</div>
So the above works but whats its actually showing on view source and what creaming frog is 404 is
href="&audience=couples" class=finder__option>
my partner and I <i
class=down-arrow></i>
</a>
<a
href="&audience=families" class=finder__option>
my family <i
class=down-arrow></i>
If either one of $image and $content are not empty .section-intro should be output to the page. i.e if both are empty .section-intro should not output. For some reason my code isn't outputting anything to page despite at least one of the fields not being empty. Any pointers as to what I'm doing wrong would be greatly appreciated.
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) || !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
construction code show be continuos like this
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
if(!empty($image) || !empty($content)){
echo "<div class='section-intro'> <div class='slides'>";
while( have_rows('image_slideshow') )
the_row();
echo " <div class='slide intro'> ";
if(!empty($image))
echo "<img src= $image['url'] >";
echo $content;
?>
</div>
</div>
</div>
Use AND instand of OR
<?php if(!empty($image) && !empty($content)): ?>
Also, your full code must be like this
<?php
if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) && !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif ?>
Use && instead of ||
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) && !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
I'm using ACF repeater and i'm trying to list only the files from Relco Components which you can see highlighted in the picture. How can i get only the specific row?
<?php if( have_rows('categorie_documentatie', 8) ): ?>
<?php while( have_rows('categorie_documentatie', 8) ): the_row();
// vars
echo $nume_categorie_doc = get_sub_field('nume_categorie_doc');
?>
<?php if( have_rows('subcategorie_doc') ): ?>
<?php while( have_rows('subcategorie_doc') ): the_row();
// vars
echo $nume_subcategorie_doc = get_sub_field('nume_subcategorie_doc');
$imagine_resursa = get_sub_field('imagine_resursa');
?>
<?php if( have_rows('fisier_doc') ): ?>
<?php while( have_rows('fisier_doc') ): the_row();
// vars
$nume_fisier_doc = get_sub_field('nume_fisier_doc');
$file = get_sub_field('file');
?>
<?php if ($nume_subcategorie_doc='Relco Components'): ?>
<a href="<?php echo $file; ?>" target="_blank">
<h5><?php echo $nume_fisier_doc; ?></h5>
</a>
<?php endif ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif; ?>
Nothing is failing in the code, i just want to get the field nume_fisier_doc just from the "Relco Components" subcategory.
I'd love to have the option to have my posts displayed in multiple columns/rows (so that I could have several thumbnails/posts horizontally laid out next to each other, instead of only being posted below one another).
I tried changing the layout but sadly nothing happened
can you suggest something?
Thank you guys :D
<?php
/**
* Legacy template for compatibility with versions prior to 2.0.0
*
* #version 2.0.0
*/
?>
<?php if ($instance['before_posts']) : ?>
<div class="upw-before">
<?php echo wpautop($instance['before_posts']); ?>
</div>
<?php endif; ?>
<?php if ($upw_query->have_posts()) : ?>
<table class="table table-bordered">
<?php while ($upw_query->have_posts()) : $upw_query->the_post(); ?>
<tr>
<?php $current_post = ($post->ID == $current_post_id && is_single()) ? 'current-post-item' : ''; ?>
<li class="<?php echo ($post->ID == $current_post_id && is_single())?'current-post-item':'' ?>">
<?php if (current_theme_supports('post-thumbnails') && $instance['show_thumbnail'] && has_post_thumbnail()) : ?>
<td>
<div class="upw-content">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail($instance['thumb_size']); ?>
</a>
<?php endif; ?>
<?php if (get_the_title() && $instance['show_title']) : ?>
<p class="post-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</p>
<?php endif; ?>
</td>
</tr>
<?php if ($instance['show_date']) : ?>
<p class="post-date">
<?php the_time($instance['date_format']); ?>
</p>
<?php endif; ?>
<?php if ($instance['show_author']) : ?>
<p class="post-author">
<span class="post-author-label"><?php _e('By', 'upw'); ?>:</span>
<?php the_author_posts_link(); ?>
</p>
<?php endif; ?>
<?php if ($instance['show_comments']) : ?>
<p class="post-comments">
<?php comments_number(__('No responses', 'upw'), __('One response', 'upw'), __('% responses', 'upw')); ?>
</p>
<?php endif; ?>
<?php if ($instance['show_excerpt']) : ?>
<?php
$linkmore = '';
if ($instance['show_readmore']) {
$linkmore = ' '.$excerpt_readmore.'';
}
?>
<p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
<?php endif; ?>
<?php if ($instance['show_content']) : ?>
<p class="post-content"><?php the_content() ?></p>
<?php endif; ?>
<?php
$categories = get_the_term_list($post->ID, 'category', '', ', ');
if ($instance['show_cats'] && $categories) :
?>
<p class="post-cats">
<span class="post-cats-label"><?php _e('Categories', 'upw'); ?>:</span>
<span class="post-cats-list"><?php echo $categories; ?></span>
</p>
<?php endif; ?>
<?php
$tags = get_the_term_list($post->ID, 'post_tag', '', ', ');
if ($instance['show_tags'] && $tags) :
?>
<p class="post-tags">
<span class="post-tags-label"><?php _e('Tags', 'upw'); ?>:</span>
<span class="post-tags-list"><?php echo $tags; ?></span>
</p>
<?php endif; ?>
<?php if ($custom_fields) {
$custom_field_name = explode(',', $custom_fields);
foreach ($custom_field_name as $name) {
$name = trim($name);
$custom_field_values = get_post_meta($post->ID, $name, true);
if ($custom_field_values) {
echo '<p class="post-meta post-meta-'.$name.'">';
if (!is_array($custom_field_values)) {
echo $custom_field_values;
} else {
$last_value = end($custom_field_values);
foreach ($custom_field_values as $value) {
echo $value;
if ($value != $last_value) echo ', ';
}
}
echo '</p>';
}
}
} ?>
</div>
</td>
</tr>
<tr>
<td>
<?php endwhile; ?>
</td></tr>
</table>
<?php else : ?>
<p><?php _e('No posts found.', 'upw'); ?></p>
<?php endif; ?>
<?php if ($instance['after_posts']) : ?>
<div class="upw-after">
<?php echo wpautop($instance['after_posts']); ?>
</div>
<?php endif; ?>
How can you get the post category on single.php?
I've tried:
<h1><?php echo $this->escapeHtml($post->get_the_category()) ?></h1>
&
<?php echo $this->escapeHtml($post->get_category_parents( $cat, true, ' ยป ' )) ?>
&
<h1><?php echo $this->escapeHtml($post->get_the_category($post->ID)) ?></h1>
This is the entire file:
<?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->get_the_category($post->ID)) ?></h1>
<h1><?php echo $this->escapeHtml($post->getPostTitle()) ?></h1>
</div>
<div class="post-view">
<p class="post-date when"><?php echo stripslashes($this->__('<span class=\"by-author\"> by %s</span> on %s.', $post->getAuthor()->getDisplayName(), $post->getPostDate())) ?></p>
<?php echo $this->getBeforePostContentHtml() ?>
<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; ?>
I'm working on WordPress through the Fishpig WordPress integration for Magento so the file path is template/wordpress/post/view.phtml.
Tomas is correct; you cannot use WordPress code in a Magento template file, even if that template file is integrating WordPress. None of the WP library code is included so the WP functions that you include do not exist.
It is still possible to get all of the WP data you require via Magento code though. To get a posts categories, use the following code:
<?php $categories = $post->getParentCategories() ?>
<?php if (count($categories) > 0): ?>
<?php foreach($categories as $category): ?>
<?php echo $this->escapeHtml($category->getName()) ?>
<?php endforeach; ?>
<?php endif; ?>
try write without $post like.
get_the_category( get_the_ID() );
instead of $post->get_the_category($post->ID)
function getPages() {
$pages = Mage::getResourceModel('wordpress/page_collection')
->addIsViewableFilter()
->orderByMenuOrder()
->setOrderByPostDate()
->load();
return $pages;
}
$pages = getPages();
foreach ($pages as $post):
Collection goes here
endforeach;