I'm working with advance custom fields. I've got a ticket in with them directly but its taking a while. I need to figure this out immediately.
Trying to repeat flexible content for a hero slider where user can add video embed or an image. How do I echo each piece in the loop properly? The content imput in Wordpress is not appearing. The containers are echoing, just no content.
<?php
if (have_rows('add_resorts_hero_image_slide', 'option')) {
while (have_rows('add_resorts_hero_image_slide', 'option')) {
the_row();
$herovideo = the_sub_field('add_resorts_hero_slider_video');
$heroimage = the_sub_field('add_resorts_hero_slider_image');
$heroimgsize = 'hero-image';
$heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize);
$heroimg_url = $heroimg_array[0];
if (have_rows('choose_resorts_hero_slider_content')) {
while (have_rows('choose_resorts_hero_slider_content')) {
the_row();
echo '<li class="orbit-slide">';
if( get_row_layout() == 'resorts_slider_video' )
echo $herovideo;
elseif( get_row_layout() == 'resorts_slider_video')
echo '<img src="'.$heroimg_url.'" />';
echo '</li>';
}
}
}
}
Just reposting the pertinent part of your code:
if( get_row_layout() == 'resorts_slider_video' ){
//Display iFrame Video (this assumes that your field is a URL field.)
echo '<iframe src="'.get_sub_field('IFRAME URL FIELD NAME GOES HERE').'"></iframe>';
}elseif( get_row_layout() == 'resorts_slider_video'){
//Display Image (this assumes that your field is an image field, being saved as an Image Object, and you want to output a custom image size)
$myImage = get_sub_field('IMAGE FIELD NAME GOES HERE');
echo '<img src="'.$myImage['sizes']['CUSTOM IMAGE SIZE NAME'].'" alt="'.$myImage['alt'].'" />';
}
Finally figured out exactly what I needed. Hoping this answer helps someone else out!
<!--ORBIT SLIDE-->
<?php
if (have_rows('add_resorts_hero_image_slide', 'option')) {
while (have_rows('add_resorts_hero_image_slide', 'option')) {
the_row();
if (have_rows('choose_resorts_hero_slider_content')) {
while (have_rows('choose_resorts_hero_slider_content')) {
the_row();
$herovideo = get_sub_field('add_resorts_hero_slider_video');
$heroimage = get_sub_field('add_resorts_hero_slider_image');
$heroimgsize = 'hero-image';
$heroimg_array = wp_get_attachment_image_src($heroimage, $heroimgsize);
$heroimg_url = $heroimg_array[0];
if( get_row_layout() == 'resorts_slider_video' ) {
echo '<li class="video orbit-slide">';
echo '<img class="background" src="http://localhost.com/vail/tier2-hero-placeholder.jpg" />';
echo '<div class="container">
<div class="watermark"></div>
<iframe id="heroorbitslider-video"
src="'. $herovideo .'"
width="100%"
frameborder="0"
scrolling="no"
allowFullscreen="true"
allowFullScreen="true"
webkitAllowFullScreen="true"
mozAllowFullScreen="true">
</iframe>
</div>';
echo '</li>';
}
elseif( get_row_layout() == 'resorts_slider_image') {
echo '<li class="orbit-slide">';
echo '<img class="background "src="'. $heroimg_url .'" />';
echo '</li>';
}
}
}
}
}
?>
<!--END ORBIT SLIDE-->
Related
I have 2 table, one for:
user information
second for:
"user last activity"
I have code to fetch and display all user on the page, each user should display his state, - everything is work as shown in my code
BUT
I want to make my code clean, so I want to move the "if
condition" in my view page to model page when the state is empty in
the table,
I want to display all my user with users state in my page without
using if condition in the view page.
My code:
DataBase:
My Page:
View:
<?php foreach($Users as $c){ ?>
<th>Firstname</th>
<th>Lastname</th>
<th>Last Activity Time</th>
<th>State</th>
<th>User ID</th>
</tr>
<tr>
<td><?php echo $c->email ?></td>
<td><?php echo $c->type ?></td>
<td><?php echo $c->last_activity ?></td>
<td>
<!-- this code is run good , but i want to change it to contolloer to make the code clean ,
and if i changed to controller hw i can call the state here -->
<?php $current_timestamp = strtotime(date("Y-m-d H:i:s") . '- 10 second');
$current_timestamp = date('Y-m-d H:i:s', $current_timestamp);
if($c->last_activity > $current_timestamp)
{
echo "online";
}
else
{
echo "offline";
} ?>
Model:
public function getAllUsers() //from 1 table
{
$this->db->select('m.user_id, m.email , m.type, u.last_activity ,u.id ,u.state');
$this->db->from('tbl_user m');
$this->db->join('tbl_user_activity u ', 'u.user_id = m.user_id' ,'LEFT');
$this->db->select_max('u.last_activity');
// $this->db->where($where);
$this->db->group_by('m.user_id');// add group_by
$query = $this->db->get();
foreach ($query as $c)
{
$current_timestamp = strtotime(date("Y-m-d H:i:s") . '- 10 second');
$current_timestamp = date('Y-m-d H:i:s', $current_timestamp);
if('$c->last_activity' > $current_timestamp) //try
{ // here must to be function to checl the last user activity and get it
// here must to set the u.state to online
}
else if($query < $current_timestamp) //try
{
}
}
return $query->result();
What if you check and set "state" in your MODEL/CONTROLLER page
MODEL PAGE
<?php
//your code,
$last_activity = $c->last_activity; //make sure it won't return NULL
if($last_activity > $current_timestamp) { //return true if online,
$state = "online";
}else{
$state = "offline";
}
//your code,
?>
just read the state in your VIEW page
VIEW PAGE
<?php
//your code,
$new_state = $c->state; //so $new_state = "online" or $new_state = "offline"
//your code,
?>
Try this.
It will create a new collection of data with a new row called 'state';
The return value is an array so you should probably change your view to loop an array instead of an object.
$query = $this->db->get()->result_result_array();
$new_record = array();
foreach($query as $old_record)
{
$current_timestamp = strtotime(date("Y-m-d H:i:s") . '- 10 second');
$current_timestamp = date('Y-m-d H:i:s', $current_timestamp);
if('$c->last_activity' > $current_timestamp) //try
{
$new_record[]['state'] = 'online';
$new_record[] = $old_record;
}
else if($query < $current_timestamp) //try
{
$new_record[]['state'] = 'offline';
$new_record[] = $old_record;
}
}
return $new_record;
I wanted to add an auto suggest list of students' code into input box
public function autoCodeSuggest()
{
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery("SELECT s.studentLogin FROM AppBundle:StudentLogin s ORDER BY s.studentLogin");
$code = $query->getArrayResult();
$strJavascript = '';
if (!empty($code)){
$strJavascript = '
var ArrayCode = new Array(';
for ($i=0; $i<count($code); $i++){
$strJavascript .= '"'.$code[$i]['studentLogin'].'",';
} // for ($i=0; $i<count($code); $i++)
$n = strlen($strJavascript)-1;
$strJavascript = substr_replace($strJavascript,'',$n); // remove last ,
$strJavascript .= ');';
} // if (!empty($code))
return $strJavascript;
} // end function
in my controller
public function studentSearchAction()
{
$LoginJS = $this->get('utilities_student_tools')->autoCodeSuggest();
return $this->render('student/student_search.html.twig', array(
'LoginJS' => $LoginJS,
));
}
student_search.html.twig contains
{% block body %}
<script language="javascript" type="text/javascript">
{{ LoginJS }}
</script>
{{ include('student_code.html.twig') }}
{% endblock %}
it doesn't work because when I view the source code of my page I have
<script language="javascript" type="text/javascript">
var ArrayCode = new Array("AA0951","AA1825","AA2802","AA2886","AA3418",.....
</script>
when I add a \ to the javascript code generator
$strJavascript .= '\"'.$code[$i]['studentLogin'].'\",';
the output become
var ArrayCode = new Array(\"AA0951\",\"AA1825\",\"AA2802\",\"AA2886\"
It works if the output is like
var ArrayCode = new Array("AA0951","AA1825","AA2802","AA2886",
the " is converted to " .
How can I avoid the conversion in twig?
I just find the answer.
{{ LoginJS|raw }}
Good morning everyone. I tried creating a site that could get information from another page and feed the response into a div tag, but it didnt work. I checked with a very similar one i learnt from. Here is the HTML code.
<html>
<head>
<script>
function checkit(){
var samxml; var username;
if (window.XMLHttpRequest){
samxml = new XMLHttpRequest();}
else {
samxml = new ActiveXObject("Microsoft.XMLHTTP");
}
samxml.onreadystatechange = function() {
if (samxml.readyState == 4 && samxml.status == 200){
document.getElementById("check").innerHTML = samxml.responseText;}
}
username = document.getElementById("username").value;
samxml.open("POST", "check.php",true);
samxml.send( "username" );
}
}
</script>
</head>
<body>
<form>
<label for ="username">User ID:</label>
<input type = "text" name = "username" id = "username"/>
<div id = "check"></div>
<button type = "button" onclick = "checkit()">Check</button>
</form>
</body>
</html>
Here is the PHP page:
//php file
<?php
$user = $_POST["username"];
if ($user == "samuel") {
echo "Hmm. Chosen! Choose another one";}
else {
echo "Nice one";}
?>
Thanks so much.
Hey guys I am trying to update a checkbox feild in my database and have to capture and bind the Values in using SQL PDO.
I am getting an error however about an array to string conversion,
my check boxes look like this -
<div class="checkboxFour">
<p class="admin_label" id="checklabel2">In Seaon</p>
<input type="checkbox" name="inSeason[]" value="1" id="checkboxFourInput" checked="checked"<?php if( isset( $_GET['inSeason'] ) ){ ?> checked="checked" <?php } ?>/>
<label for="checkboxFourInput"></label>
</div>
<div class="checkboxFour">
<p class= "admin_label"id="checklabel2">Out Season</p>
<input type="checkbox" name="inSeason[]" value="0" id="checkboxFour2Input" <?php if( isset( $_GET['inSeason'] ) ){ ?> checked="checked" <?php } ?> />
<label for="checkboxFour2Input"></label>
</div>
In my PHP I have built the following -
if (isset($_POST['updateProductSubmit'])) {
// open the database connection
include 'includes/connection.php';
$inSeasonValue = "0";
if( array_key_exists( 'inSeason', $_GET ) && $_GET['inSeason'] == '0' ){
$saleItemValue = "0";
echo $saleItemValue['inSeason'];
}
$inSeasonValue = "1";
if( array_key_exists( 'inSeason', $_GET ) && $_GET['inSeason'] == '1' ){
$saleItemValue = "1";
echo $saleItemValue['inSeason'];
}
try {
//create our sql update statement
$sql = "UPDATE Products SET productNbr = :productNbr, productName= :productName, inSeason = '$inSeasonValue', description = :description, photo =
:photo WHERE productNbr=:productNbr;";
// prepare the statement
$statement = $pdo->prepare($sql);
// bind the values
$statement->bindValue(':productNbr', $_POST['productNbr']);
$statement->bindValue(':productName', $_POST['productName']);
$statement->bindValue(':inSeason', $_POST['inSeason']);
$statement->bindValue(':description', $_POST['description']);
$statement->bindValue(':photo', $_POST['photo']);
// execute the statement
$success = $statement->execute();
} // end try
catch (PDOException $e) {
echo 'Error updating item: ' . $e->getMessage();
exit();
} // end catch
// test the result and display appropriate message
if ($success) {
echo '<script type="text/javascript"> alert("Successfully updated Item.")</script>';
}
else {
echo '<script type="text/javascript">alert("Unable to execute the Item update.");</script>';
}
//free connection to the server
$statement->closeCursor();
} // end if statement
?>
The error is pointing out that the bind value $statement->bindValue(':inSeason', $_POST['inSeason']);
I hope you guys can help!!
Thanks so Much in advance!!
:-)
You have named your inSeason checkox with an array construct here
<input type="checkbox" name="inSeason[]" value="0" id="checkboxFour2Input" <?php if( isset( $_GET['inSeason'] ) ){ ?> checked="checked" <?php } ?> />
This will appear as an array when PHP decodes th $_GET data, but here
if( array_key_exists( 'inSeason', $_GET ) && $_GET['inSeason'] == '0' ){
You're testing against a string, hence the array-to-sring error message.
Simply rename your checkBox in your HTML like this:
<input type="checkbox" name="inSeason" value="0" id="checkboxFour2Input" <?php if( isset( $_GET['inSeason'] ) ){ ?> checked="checked" <?php } ?> />
^^^ remove square brackets here.
Is there a way to display a blob image in TCPDF in Yii? I've tried calling this function but it doesn't show any pictures.
public function actionDisplayAgencyIcon()
{
$info = BaseAgencyInfo::model()->find();
$id = $info->agencyID;
if($id == null || trim($id)=='') {
echo "error in image, bad ID value [{$id}]";
exit();
}
$model=BaseAgencyInfo::model()->find("agencyID = '{$id}'");
if($model->agency_logo == null){
echo "error in image, using ID [{$id}] ";
exit();
}
header('Content-Type: gif,jpeg,png');
echo $model->agency_logo;
}
Any ideas?
Try to specify a proper header:
header('Content-Type: image/jpeg');
echo $model->agency_logo;