Having a bit of a problem, i'm using ACF for WordPress, i have defined the color picker on the services template which color codes the page heading in a color you select. This template then has a page link which relates to another template: case studies - the case studies template has a select option where you select the page from services that relates to the case study. I can get those values out as it is on the case studies template. How do i go about getting the color picker value from the services page and apply the color to the case studies page? Here is what i have done so far;
<div class="caseStudies">
<h1 class="pageTitle uppercase"><?php echo the_title(); ?></h1>
<div class="caseStudyIntro"><?php echo the_content(); ?></div>
<?php
foreach($caseStudyChildren as $caseStudies)
{
$cStudyId = $caseStudies->ID;
$cStudyThumbnail = get_field("thumbnail_image", $cStudyId);
$cStudyRelation = get_field("case_study_relation", $cStudyId);
$cStudyContent = get_field("case_study_content", $cStudyId);
?>
<div class="caseStudyItem">
<div class="col-md-3 noPaddingLeft">
<a href="<?php echo get_permalink($cStudyId); ?>">
<img src="<?php echo $cStudyThumbnail['url']; ?>" alt="<?php echo $cStudyThumbnail['alt']; ?>" class="img-thumbnail cStudyThumb" />
</a>
</div>
<div class="col-md-9 noPadding">
<div class="content">
<h1 class="title uppercase">
<a href="<?php echo get_permalink($cStudyId); ?>" class="dark-black">
<?php echo get_the_title($cStudyId); ?> <?php echo '- '.$cStudyRelation; ?>
</a>
</h1>
<div class="study">
<?php echo wp_trim_words($cStudyContent, 40, '...'); ?>
</div>
Read More...
</div>
</div>
</div>
<div class="clearfix"></div>
<?php
}/* foreach end */?>
</div>
This line here is where i am adding the services link that relates to the case study (so it almost acts like a tag)
<?php echo get_the_title($cStudyId); ?> <?php echo '- '.$cStudyRelation; ?>
Backend Configuration
Hope that made some sense, if not let me know and i can add to it more. PHP newbie here so go easy one me, haha!
Thanks.
Managed to figure this out in the end. I've got the relationship to the page coming out now and now i've got the color custom field that was defined on the services template coming out on the case studies page.
So i defined the field name in a variable;
$cStudyRelationship = get_field("service_case_study_relationship", $cStudyId);
Then did the following;
$cStudyRelationshipId = '';
$caseStudyTitleColor = '#000';
if(isset($cStudyRelationship[0])){
$cStudyRelationshipId = $cStudyRelationship[0]->ID;
$caseStudyTitleColor = get_field("case_study_title_colour",$cStudyRelationship[0]->ID);
$caseStudyTitleColor = '#'.ltrim(trim($caseStudyTitleColor),'#');
} ?>
So built up the array for the color field created in ACF and then echoed that out against the ID the case study was related to. Hope that makes sense! Not the best at explaining stuff as you can tell.
The last piece of the jigsaw was to apply the color value against the page relationship page title;
<?php echo get_the_title($cStudyId); ?> <?php echo '- '?> <span class="colouredTitle" style="color:<?php echo $caseStudyTitleColor; ?>;"><?php echo ($cStudyRelationship[0]->post_title); ?></span>
Thank you to those that have taken the time out to contribute to this question.
Related
I have a simple MySQL table that stores four fields - CATEGORY, TITLE, DESCRIPTION, IMAGE as well as a unique ID for each row.
I use ORDER BY CATEGORY to display all of them on the page through one query.
SELECT
RESOLUTIONS.CATEGORY,
RESOLUTIONS.ID,
RESOLUTIONS.TITLE,
RESOLUTIONS.DESCRIPTION,
RESOLUTIONS.IMAGE
FROM
RESOLUTIONS
ORDER BY
RESOLUTIONS.CATEGORY
I want to create a jump menu that will jump to the first row of each category on the page. Is this possible using php? I know how to create a jump menu that jumps to an ID anchor of a div, but how can I make a unique identifier (that I can jump to) inside the repeat region?
Here is the repeat code I have now...
<?php
while(!$DETAILS->atEnd()) {
?>
<div class="row g-my-10 g-color-black">
<?php if($DETAILS->getColumnVal("IMAGE")!= "") { ?>
<div class="col-md-9">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>
</div>
<div class="col-md-3"><img src="images/<?php echo($DETAILS->getColumnVal("IMAGE")); ?>" class="img-fluid"></div>
<? } else { ?>
<div class="col-md-12">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>
</div>
<?php } ?>
</div>
<?php
$DETAILS->moveNext();
}
$DETAILS->moveFirst(); //return RS to first record
?>
In each iteration check if the category is different than the one before and create an anchor.
<?php
// set any initial value that does not match an empty category (if you have them)
$lastCategory = false;
while(!$DETAILS->atEnd()) {
<div class="row g-my-10 g-color-black">
<?php
// this category is different than the last: create anchor
if ($lastCategory !== $DETAILS->getColumnVal("CATEGORY")) {
echo '<a name="category-' . $DETAILS->getColumnVal("CATEGORY") . '"></a>';
// set the compare-value to the current category
$lastCategory = $DETAILS->getColumnVal("CATEGORY");
}
?>
<?php if($DETAILS->getColumnVal("IMAGE")!= "") { ?>
<div class="col-md-9">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>
</div>
<div class="col-md-3"><img src="images/<?php echo($DETAILS->getColumnVal("IMAGE")); ?>" class="img-fluid"></div>
<? } else { ?>
<div class="col-md-12">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>
</div>
<?php } ?>
</div>
<?php
$DETAILS->moveNext();
}
$DETAILS->moveFirst(); //return RS to first record
?>
Note: You might have to put the anchor within the column or even the <h2>, depending on your grid system (is that bootstrap?). You maybe also want to refactor the generation of the title/description column, so you don't repeat yourself. Something like
<?php
if ($DETAILS->getColumnVal("IMAGE")!= "") {
$cols = '9';
} else {
$cols = '12';
}
?>
<div class="col-md-<?php echo $cols ?>">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>
</div>
<?php
if ($DETAILS->getColumnVal("IMAGE")!= "") {
?>
<div class="col-md-3"><img src="images/<?php echo($DETAILS->getColumnVal("IMAGE")); ?>" class="img-fluid"></div>
<?php
}
?>
Also note that according to PSR-1 you should use either <?php or the echo shortcut <?= but not just <?
And I know it's a matter of personal choice and also depends on what your file mainly contains (HTML or PHP), but I personally prefer echoing HTML code snippets instead of opening and closing PHP tags, because I find it easier to read (there is also a very marginal performance advantage)
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>
I have been fixing this store, based on magento. The main problem of this is that Some of the products display on the store view has incorrect size (which is attribute)
If you have a look at the picture, on the grid view (list.phtml) the size is US 16/ UK 18 / EUR 48 while on the single view page (view.phtml) it is US 6/ UK 8/ EUR 38.
Have a look at this link
http://www.sequinqueen.com/shop/in-stock.html
I have gone through the code in the view.phtml and appear that the code request the attribute value correctly according to the code below
<?php
$categories =$_product->getCategoryCollection();
foreach($categories as $_category) {
$cat_arr[] = $_category['entity_id'];
}
if($currentCategoryId==102){
// CATEGORY ID = 102 is IN-STOCK PRODUCT CATEGORY
$sizeStock=$_product->getAttributeText('size');
$day="Ready To Ship";
$searchfabric=$_product->getSearchfabric();
$searchcolor=$_product->getSearchcolor();
$make=$_product->getHandmake();
$handmake="HandMake";
$topname=$_product->getTopname();
<?php $i=$j+1;?>
<?php $j=$j+1;?>
<?php if($j<5){?>
<?php if ($i%$_columnCount==1): ?>
<ul class="products-grid">
<?php endif ?>
<?php if($j==1):?>
<li class="item first" style="height:434px; background:#FFF;">
<?php echo $this->getChildHtml("catalog"); ?>
</li>
<li class="item">
<?php echo $topname; ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(162,324); ?>" width="162" height="324" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div style="width:100%; border-bottom:none; height:80px;">
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($make==1){ echo "<p>".$handmake."</p>";}else{}?>
<?php if($currentCategoryId==102){?>
<!-- display size -->
<p><?php echo $sizeStock; ?></p>
<?php } ?>
<p> <?php echo $day; ?></p>
</div>
</li>
so it came to my thought that it might be something in the store backend, somewhere around attribute modification.
Here is how the previous developer sorted and arranged the position of the size values I am not sure if this is the cause of problem.
Anybody is familiar with this problem?
Any answer is appreciated.
thank you in advance.
Did you try to reindex product data from "System"->"Index Management" ?
Please use this
$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);
I am working on running website which is loading main.php file on Each page and it has thousands of pages. Each page url is different e.g,
mywebsite.com/United-Kingdom.php
and
mywebsite.com/United-Stats-of-america.php.
each page having unique page title which is being load by PHP from Database,
(<h4 style="font-size:20px;color:#148ADB;"><?php echo $cityname['country']; ?>Information</h4>).
i want to change header jpg image automatically with url or with page title e.g if user go united-kingdom url than image should be loaded /images/country/united-kingdom.jpg on header and when user open United Stats page it should load image /images/country/united-stats.jpg on header.
How can i achieve this ?
= now() ORDER BY fare");
$arr1=mysql_fetch_array($sel1);
?>
<div id="content-top-txt" style="height:auto">
<div id="content-top-inner1">
<div id="content-top-txt-inner1" style="height:auto">
<div class="content">
<h4 style="font-size:20px;color:#148ADB;"><?php echo $cityname['country']; ?>specials</h4>
<p style='text-align:justify; font-size:13px; color:#3c3c3c;'>
<strong style="text-transform:uppercase;color:#148ADB;"><?php echo $cityname['country']; ?></strong> with choice of range prices think of comfort for lesser cost<strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong> starts from <?php
$tempcode=$arr1['des_code'];
$stemp=mysql_query("SELECT * FROM cities_var WHERE code='$tempcode'");
$temp=mysql_fetch_array($stemp);
if($temp['code']=='')
{
?>
<strong><?php echo $arr1['des_name'];?> (<?php echo $arr1['des_code']; ?>) </strong>
<?php
}
else
{
?>
<strong><?php echo $arr1['des_name'];?> (<?php echo $arr1['des_code']; ?>) </strong>
<?php
}
?>
# <strong>£<?php echo $arr1['fare']; ?></strong> with & table below<?php echo $arr1['des_name'];?> & other cities in <strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong> About<strong>UK</strong>.General information About <strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong>call # 123456789 or use Form or email:- <strong>Email#address.com</strong></p>
<p><?php echo $cvar['overview2']; ?></p>
<p>Note:-Prices given are excluding taxes</p>
</div>
<div id="content-top-inner2">
<div id="content-top-txt-inner2" style="height:auto">
<!-- slider start here -->
<div class="slider-main">
</div> <!-- slider end here-->
</div><!-- Content-top-txt-inner2 end-->
</div><!-- content-top-inner2 end here-->
</div><!--contaent-top-txt end here -->
</div><!--content-top end here -->
<div id="content-middle">
<div id="content-middle-txt">
<?php
include("../../files/lb1.php");
?>
<div class="content-middle-txt-right">
<?php
include("../../files/d-search-compare.php");
?>
</div>
<div style="clear:both"></div>
<div class="more"><p><span>Note : </span><?php //echo $sql_rec['note']; ?></p><p>paragraph text.</p>
</div> <!--content-middle-txt end -->
</div> <!--content-middle end -->
<div id="content-bottom">
<div id="content-bottom-txt">
<div id="bottom-all-box">
<?php
include("../../files/lb2.php");
?>
<div id="content-bottom-right">
<?php
include("../../files/rb1.php");
?>
</div>
</div>
<?php
/*
include("../../files/country-left-box3.php");
include("../../files/country-right-box1.php");
*/
?>
I would change all the image names to the exact page name of the PHP file. So for example you have /united-kingdom.php your image should be named united-kingdom.jpg.
With that the same you can get the current page URL which you requested using $_SERVER['REQUEST_URI'].
Now you can define the image using the current page name.
$url= $_SERVER['REQUEST_URI'];
$imageName = substr($url, 0, strpos($imageName, "."));
The variable $imageName will contain united-kingdom.
So you can define your image like:
<img src="<?php echo $imageName; ?>.jpg" alt="" />
This code is not completely tested but is just to give you an idea on how you can handle it.
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.