Jump to content

getting duplicate result


zaib
 Share

Recommended Posts

I'm fetching some results on the basis of categories check boxes (which are checked only).

until here works fine,

issue is if multiple check boxes are selected so given result is also duplicating

<?php
$getCities = $page->find("template=t3Cities_list");
foreach ($getCities as $city) {
    foreach ($city->tags as $get) {
        $getTags = $page->get("template=tags_template, include=hidden")->children("sort=title, tag_code={$get->title}");
        
        echo "<div class='grid-masonry'><div class='grid-sizer'></div>";
        foreach ($getTags as $tag) {
            echo "<div class='grid-item'>
							<a href='{$tag->url}' class='img-hovered'>
								<div class='overlay'>
									<span>{$tag->title}</span>
									<!--<div class='cat-subtitle'>{$tag->categorymeta}</div> -->
								</div>

								<img class='img-responsive' src='{$tag->categorythumb->url}{$tag->categorythumb}' />

							</a>
					  </div>";
        }
        echo "</div>";
    }
}
?>

$getTags = $page->get("template=tags_template, include=hidden")->children("sort=title, tag_code={$get->title}");

this {$get->title} is the value of checkbox

home.png

Link to comment
Share on other sites

I'm trying to wrap my head around your page structure, is it something like this? Can you post a screenshot?

$page
|
+--t3Cities_list
+--t3Cities_list
|
+--tags_template
|   |
|   +--tag
|   +--tag
|
+--tags_template
    |
    +--tag
    +--tag

I've cleanup your code, and what does $getCities do? Are you listing`t3Cities_list` pages and their tags (depending on checkboxes)

<?php namespace ProcessWire;
/** @var $page Page */

$getCities = $page->find("template=t3Cities_list"); ?>

<?php foreach ($getCities as $city): ?>
    <?php foreach ($city->tags as $get): ?>
        <?php $getTags = $page->get("template=tags_template, include=hidden")->children("sort=title, tag_code={$get->title}"); ?>

        <div class="grid-masonry">
            <div class="grid-sizer">

                <?php foreach ($getTags as $tag): ?>
                    <div class="grid-item">
                        <a href="<?= $tag->url ?>" class="img-hovered">
                            <div class="overlay"><span><?= $tag->title ?></span></div>
                            <img src="<?= $tag->categorythumb->url . $tag->categoryThumb ?>" alt=""
                                 class="img-responsive">
                        </a>
                    </div>
                <?php endforeach; ?>

            </div>
        </div>

    <?php endforeach; ?>
<?php endforeach; ?>

 

 

  • Like 2
Link to comment
Share on other sites

Or maybe "tags" is a Page Reference field and you can do this...

<?php $getCities = $page->find("template=t3Cities_list"); ?>
<?php foreach($getCities as $city): ?>
    <div class="grid-masonry">
        <div class="grid-sizer"></div>
        <?php foreach($city->tags->sort('title') as $tag): ?>
            <div class="grid-item">
                <a href="<?= $tag->url ?>" class="img-hovered">
                    <div class="overlay"><span><?= $tag->title ?></span></div>
                    <img src="<?= $tag->categorythumb->url . $tag->categoryThumb ?>" alt="" class="img-responsive">
                </a>
            </div>
        <?php endforeach; ?>
    </div>
<?php endforeach; ?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...