Flexslider with php multiple videos - php

I have a table "videos" with id_video, client, code. And i found this:
http://demo.juanfra.me/multiple-videos-flexslider-v2/
First i tried put the -li- into a while and show all results with mysqli_fetch_array.
But i cant show anything. I think the id of each iframe "player_number" must be unique, so do i have to use a for()?
<?php while($rowmulti = mysqli_fetch_array($resultmultimedia)){
echo'
<li>
<iframe id="player_1" src="http://player.vimeo.com/video/'.$rowmulti["code"].'?api=1&player_id=player_1"></iframe>
</li>
';}?>
Maybe the error is in the jquery code but i dont good js programmer. thank you!

You don't necessarily need a for loop. You can just keep track of an $id variable within the loop that increments each iteration.
Try this:
<?php
$id = 1;
while ($rowmulti = mysqli_fetch_array($resultmultimedia)) {
echo'
<li>
<iframe id="player_' . $id . '" src="http://player.vimeo.com/video/' . $rowmulti["code"] . '?api=1&player_id=player_' . $id . '"></iframe>
</li>';
$id++;
}
?>

Related

inserting a variable within another variable string that contains an if statement

I have a string as follows and store it in the variable:
$div = '<div class="posts"> . $row['author'] .'<?php if('.$perm.'>1):?><br>  '.$role.'</br>  Edit<?php endif ?></div>
What I want is to use this variable in another page so I need to insert the if statement to regulate permission so the content only displays with those users with above 1. It comes up with no syntax errors but when I run it this happens
John1):?>
Moderator
Edit
so the 1):?> is being displayed when it shouldn't.
Any reasons why? or how I could do this better?
Thanks.
Can you give an try like this:
$div ='<div class="posts">'.$row['author'].''; ?> <?php if($perm>1) {'<br>  '.$role.'</br>  Edit';} ''
I think its badly formated with single quotes ' , please check and lets see if it is.
Try conditional operator like this. The div section is kept at both statements just to improve readability.
$div = if('.$perm.'>1) ? ('<div class="posts"> . $row['author'] . <br>  '.$role.'</br>  Edit<div>') : ('<div class="posts"> . $row['author'] .'<div>');
Or:
$div = '<div class="posts"> . $row['author'] .';
$div += if('.$perm.'>1) ? '<br>  '.$role.'</br>  Edit<div>' : '<div>';

Referencing data in MYSQL database on Wordpress Site

I have a basic table in a wordpress site that looks like this: https://jsfiddle.net/4fcpdgs8/
Right now the table is hard coded with values found in the html but ideally I would like it to be dynamic based on the values in the MYSQL database. I have seen some solutions that involve php such as:
global $wpdb;
// this adds the prefix which is set by the user upon instillation of wordpress
$table_name = $wpdb->prefix . "your_table_name";
// this will get the data from your table
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
?>
<ul>
foreach ($retrieve_data as $retrieved_data){ ?>
<li><?php echo $retrieved_data->column_name;?></li>
<li><?php echo $retrieved_data->another_column_name;?></li>
<li><?php echo $retrieved_data->as_many_columns_as_you_have;?></li>
<?php
}
?>
</ul>
<?php
But one wrinkle is that one column is a url for an html image tag so doing the above just displays the url.
So, I would rather do something that would enable me to just reference the sql results like:
<img src=[mysql_image_column_row_one]>
<img src=[mysql_image_column_row_two]>
Rather than just displaying the sql results in a table. Sidenote: I know very little php and it is quite mysterious to me!
you can use this for images
<?php echo '<img name="myimage" src=' . $retrieved_data->column_name
. ' width="60" height="60" alt="imagedesciription" />'?>;
You must adept the image size or even resize the image.
You can use img tag with an image path inside li tag in foreach loop.
<li><img src='path_to_image_folder/<?php echo $retrieved_data->image_name?>'></li>

Advanced Custom Fields in Wordpress - "if" statement troubles

I was hoping somebody may be able to help me. I'm having trouble with if statements with the Advanced Custom Fields plugin for Wordpress. I've got three options the user can choose from, all three can be chosen, but they can also choose just one if they wish.
The issue I'm having is the code I've written displays all of the HTML tags, even the empty ones. This is causing styling issues. I want to be able to just show HTML that has been populated. I've tried the solutions on the ACF forums but to no avail.
Link: http://www.advancedcustomfields.com/resources/getting-started/code-examples/
Here's the quick (newbie!) code I've got at the minute:
<?php the_sub_field('link'); ?>
<?php the_sub_field('doc'); ?>
<p><?php the_sub_field('cap'); ?></p>
I looked on the ACF forum and tried this, but it broke the theme:
<?php if(the_sub_field('link')) {
echo '' . the_sub_field('link') . '';
} ?>
<?php if(the_sub_field('doc')) {
echo '' . the_sub_field('doc') . '';
} ?>
<?php if(the_sub_field('cap')) {
echo '<p>' . the_sub_field('cap') . '</p>';
} ?>
I'm looking for some help to make this work. I don't think I'm too far away from the right answer, however I'm a bit of a rookie with anything beyond standard front-end stuff, any thoughts would be very much appreciated.
Thanks!
Try to use get_sub_field();
<?php if(get_sub_field('link')) {
echo '' . the_sub_field('link') . '';
} ?>
<?php if(get_sub_field('doc')) {
echo '' . the_sub_field('doc') . '';
} ?>
<?php if(get_sub_field('cap')) {
echo '<p>' . the_sub_field('cap') . '</p>';
} ?>
When looping through one of these fields, this function returns a sub field from the current row.
Like Dk-Macadamia said, try to use get_sub_field() in loops instead of the_sub_field()
the difference is get_sub_field() return the value as a string, and the_sub_field() print the data,
Also get_sub_field() only work under a repeater/ fluid field type otherwise wont work,
if its not a sub field of repeater/fluid fields just try get_field()

PHP and Concrete 5 count subpages

Making mobile site with Concrete5 and using page list block with custom template. I'm trying to count sub pages using PHP.
<?php foreach ($pages as $page):
// Prepare data for each page being listed...
$title = $th->entities($page->getCollectionName());
$url = $nh->getLinkToCollection($page);
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
$target = empty($target) ? '_self' : $target;
$description = $page->getCollectionDescription();
$description = $controller->truncateSummaries ? $th->shorten($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$mies = 0;
?>
<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" data-theme="c"><div aria-hidden="true" class="ui-btn-inner ui-li"><div class="ui-btn-text"><a target="<?php echo $target ?>" class="ui-link-inherit" href="<?php echo $url ?>">
<h2 class="ui-li-heading"><?php echo $title ?></h2>
<p class="ui-li-desc"><?php echo $description ?></p>
</a>
</div><span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span><span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo count($mies) ?></span></div></li>
<?php endforeach; ?>
So, probably need to use Count function(or length?), I don't know. If I am editing wrong place please advice if you have any experience in Concrete5 cms.
If you want to show the corresponding page number in the span element in your code:
<span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo $mies; ?></span>
If you want to show the remaining sub-pages, then in the html code snippet above just replace $mies with count($pages) - $mies like:
<span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo count($pages) -$mies; ?></span>
You would first have to initialise $mies before you start the forloop so it should be something of the form:
<?php
$mies = 0;
foreach ($pages as $page):
//Rest of your code and increment $mies with every iteration
$mies ++; //This ensures that you are counting the corresponding pages
?>
If you want to get the count of total number of sub-pages, you just have to echo out $mies outside the for block may be like:
<?php
endforeach;
echo $mies; //Shows you the total number of pages processed inside the for loop.
//or Just find the length of pages array
echo count($pages);
?>
As far as getting the length of array is concerned you could use count or sizeof. I stumbled upon a SO question about using count or sizeof method for finding the length of an array.
This should get you started in the right direction.
You need the parent ID;
$parentId = Page::getCollectionParentId();
Note that Page::getCollectionParentId() gets the current page's parent ID,so you may want to try;
$parentId = $page->getCollectionParentID();
Then create a new PageList to filter with and filter by the parentId;
Loader::model('page_list');
$pl = new PageList();
$pl->filter(false, '(p1.cParentID IN ' . $parentId . ')');
// Get the total
var_dump($pl->getTotal());
This is untested but the theory makes sense.
This is likely a bit simpler.
$pl->getTotal()
$pl is the PageList object that is set in the controller.
Also, these days you can just use the h() method instead of writing out $th->entities()
Edit: I should clarify that you don't need to do a $pl = new PageList() because $pl is already set to the PageList object in the controller and passed to the view.

pass link text to next page

For my actual web-project, I made a tagcloud. When I click on a tag, it should be passed to the page showRecipesFromTags.php.
<form name="tagform" id="tagform" method="get" action="/showRecipesFromTags.php">
<?php
include('php/getRandomTags.php');
$tagsarr = json_decode($return4634, true);
foreach ($tagsarr['Data']['Tag'] as $key => $tag11) {
echo '<a id="seastags" href="#" onclick="document.tagform.submit()"><font size="' . rand(1,4) .'">' . $tag11['Tag_name'] . '</font> <br/></a> ';
}
?>
</form>
It can already go to this page by clicking on the href, but what I need is to pass the id of the clicked tag. The name of the tag is called Tag_name. The name is shown but I don´t know how the pass the id to the next site. The id is in my JSON array and is called Tag_id.
How can I manage this?
Why do you even need a form? Just use plain links.
Try using this in the foreach loop:
echo '<a id="seastags" href="/showRecipesFromTags.php?tagId=' .$tag11['Tag_id'] . '"><font size="' . rand(1,4) .'">' . $tag11['Tag_name'] . '</font> <br/></a> ';
Your choice are:
use a hidden field
put it in the URL
use a cookie

Categories