ACF repeater get specific row by name - php

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.

Related

Screaming frog sees a link to a page which is not there but shows

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>

Multiple PHP if statements

My code below is checking to see if a Wordpress member is male or female, and the displaying certain code based on this. I am trying to optimise the code below to avoid having to have 2 copies of the entire code block, as it appears to me that I only need to conditionally check the first piece of ACF if code, as this is referring to the gender specific content? How can I achieve this?
The current code below is working correctly, but results in lots of duplicate code. The attempt below does not work, it appears to be getting confused with the <? endif; ?> tags?
CURRENT
<?php if ($memberGender == "male") : ?>
<section>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<div class="accordion-section">
BOY SPECIFIC CONTENT
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>
<?php if ($memberGender == "female") : ?>
<section>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<div class="accordion-section">
GIRL SPECIFIC CONTENT
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>
ATTEMPT
<section>
<?php if ($memberGender == "male") : ?>
<?php if( have_rows('accordion_section_boys') ): ?>
<?php while( have_rows('accordion_section_boys') ): the_row(); ?>
<?php endif; ?>
<?php if ($memberGender == "female") : ?>
<?php if( have_rows('accordion_section_girls') ): ?>
<?php while( have_rows('accordion_section_girls') ): the_row(); ?>
<?php endif; ?>
<div class="accordion-section">
GENDER SPECIFIC CONTENT (BOY OR GIRL)
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php endif; ?>
<section>
<?php if ($memberGender == "male") : ?>
<?php $val = 'accordion_section_boys';?>
<?php endif; ?>
<?php if ($memberGender == "female") : ?>
<?php $val = 'accordion_section_girls';?>
<?php endif; ?>
<?php if( have_rows($val) ): ?>
<?php while( have_rows($val) ): the_row(); ?>
<div class="accordion-section">
BOY SPECIFIC CONTENT
</div>
<?php endwhile; ?>
<?php endif; ?>
<section>
I would suggest something like:
<?php
$genders = array(
'male' => 'accordion_section_boys',
'female' => 'accordion_section_girls',
);
foreach ( $genders as $gender => $rows_id ) {
while( have_rows( $rows_id ) ) {
// Here use a template to print the content, by name them like "template-male" and "template-female"
include 'template-' . $gender . '.php';
}
}
?>
If you notice the code, I told you to use a template to show the HTML, so you can call them dynamically and the content will be:
<section>
<div class="accordion-section">
CONTENT
</div>
</section>
Because they have the same structure you can do something like this:
<?php
if ($memberGender == 'male' || $memberGender == 'female'){
$indicator = ($memberGender == 'male')? 'boys' : 'girls';
if( have_rows('accordion_section_'.$indicator) ){
while( have_rows('accordion_section_'.$indicator) ){
the_row();
}
}
}
?>

Wordpress posts under content

How should look my code in order to display a preview of a categories with main main page?
Now its is
<?php $posts = get_posts ("category=2&orderby=date&numberposts=3"); ?>
<?php if ($posts) : ?>
<?php foreach ($posts as $post) : setup_postdata ($post); ?>
<div>
<?php the_title(); ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
and below this
<?php if(have_posts()): ?>
<?php while(have_posts()): the_post(); ?>
<div class="pageContainer"><?php the_content(); ?></div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?><div>Sorry, posts are not found.</div>
<?php endif; ?>
This leads to ignore second part...
Sorry for my english.
<?php
// Category posts
$posts = get_posts("category=2&orderby=date&numberposts=3");
if ($posts){
foreach ($posts as $article){
echo '<div><a href="'.get_permalink($article->ID) ?>" rel="bookmark">'.
$article->post_title.'</a></div>';
}
}
// Current page content
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<div class="pageContainer">
<?php the_content(); ?>
</div>
<?php endwhile;
else:
echo '<div>Sorry, posts are not found.</div>';
endif;
?>

how to display odd number post in left side even number post in right side?

<?php $counter = 3; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if ( in_category('3') ): ?>
<?php else: ?>
<?php endif; ?>
<?php if($counter%2 == 0){echo 'floatRight';} else { echo 'floatLeft'; } ?>
<?php the_ID(); ?>
<h1 > <?php the_title(); ?></h1>
<?php the_post_thumbnail('full'); ?>
<?php the_content(__('(more...)')); ?>
<?php comments_template(); // Get wp-comments.php template ?>
<?php if($counter%2 == 0){ echo "<div class='clear'></div>";} ?>
<?php $counter++; ?>
<?php endwhile; else: ?>
<?php endif; ?>
i am trying to display in this way and i want to display particular category of post
post1
post2
post3
post4
please give me the solution ...
use the below code.
<?php while(have_posts()) : ?>
<?php $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
<?php the_content(); ?>
<?php endif; endwhile; ?>
<?php $i = 0; rewind_posts(); ?>
<?php while(have_posts()) : ?>
<?php $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
<?php the_content(); ?>
<?php endif; endwhile; ?>
You can use this css3 property to do it (This would take care odd and even elements, you don't have to write down the loop explicitly):
p:nth-child(odd) //you can do the same for div
{
float:left;
}
p:nth-child(even)
{
float:right;
}
You can use query_post() or Wp_query() in wordpress .
Use this code. to get the particular categories post .
<?php
// The Query
query_posts( 'cat=3' );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>

wordpress WPML advanced fields relationship

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

Categories