Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I have got multiple php variables that I want to display in html <ul list. The variables being displayed but not how I want it to be. It seems like one <li is inside of <ul correctly but, the other one is outside of <ul in it's own block and it's own <li even when I am displaying all of the variables inside of single <ul. Also the styling is only being applied to only the first <li element and not to the others.
Here is my html code
<div>
<ul class="product-info-list">
<li> <?php echo $dimensions; ?> </li>
<li> <?php echo $materials; ?> </li>
<p> <?php echo $description; ?> </p>
</ul>
</div>
The source code from page source is
<div class="product-info-details">
<div>
<ul class="product-info-list">
<li> 18" x 10" x 6".</li>
</ul></li>
<li> Burlap,Nylon,Polyester </li>
<p> <p>With the Fusion Backpack strapped on, every trek is an adventure - even a bus ride to work </p>
</ul>
</div>
and the output
The html structure that is getting created after doing what I am doing is,
The page element cant be where you have it. The <p> can not be between the </li> and </ul>. I can not find a suitable authoritative reference right now, but I have made the same mistake myself.
So I have shifted it inside the <li>..</li>
Try this.
<div>
<ul class="product-info-list">
<li> <?php echo $dimensions; ?> </li>
<li> <?php echo $materials; ?>
<p> <?php echo $description; ?> </p></li>
</ul>
</div>
Or maybe you intended this. I have changed the <p> to a list element
<div>
<ul class="product-info-list">
<li> <?php echo $dimensions; ?> </li>
<li> <?php echo $materials; ?> </li>
<li> <?php echo $description; ?> </li>
</ul>
</div>
Related
I am working on a HTML code as shown below in which I want to control li tags through php code.
HTML Code:
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
php code:
<input type="text" name="no_articles_EN" style="width: 77.69px;height: 22px;" value="<?php if($data->{"no_articles_EN"}<>''){echo $data->{"no_articles_EN"};} ?>"> // Line#A
<input type="text" name="no_articles_FR" style="width: 77.69px;height: 22px;" value="<?php if($data->{"no_articles_FR"}<>''){echo $data->{"no_articles_FR"};} ?>"> // Line#B
At Line#A on php code above, let say if the value entered is 3(no_articles_EN), then li tags should be 3 as shown below:
HTML Code:
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
And if the value entered 2(no_articles_EN) then li tags should be 2 as shown below:
HTML Code:
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
Problem Statement:
I am wondering what changes I should make in the HTML code above so if no_articles_EN is 3/4/5 then li tags should be vice versa. I came with the following logic but I think I need to more in it.
<?php
if($data->{"no_articles_EN"}) // Let say when no_articles_EN is 3 then li tags should be 3.
{
?>
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
<li class="vidlist-main__item cf">
</li>
<?php
}
?>
If $data->no_articles_EN is an integer equal to the number of items you want. Which is what it appears to be you can use a simple for loop.
if the value entered is 3(no_articles_EN), then li tags should be 3
if the value entered 2(no_articles_EN) then li tags should be 2 as shown below:
I prefer the ALT PHP syntax when working with mixed content (PHP/HTML) it's just cleaner. But if you prefer the {...} by all means use that. The alt syntax uses a : and end{command}; instead of the {}. It's just easier to move the code around like this, easier to find the end tags etc.
<?php if($data->no_articles_EN): ?> // Let say when no_articles_EN is 3 then li
<?php for($i=0; $i<$data->no_articles_EN; ++$i): ?>
<li class="vidlist-main__item cf"></li>
<?php endFor; ?>
<?php endif; ?>
You shouldn't use the variable property syntax $data->{"no_articles_EN"} unless you really need it, as it reduces readability and adds complexity when it's not needed. That is mainly for things like this $data->{"no_articles_".$language} where you could have part of the property name as a variable.
Cheers!
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to create an if else statement where if the "if" part is true, a menu icon is displayed that says "Registration" and takes the user to a registration page. If the "else" part is true, the menu will display the user's name that is registered. I have attached basically how I would like it to look, I just do not know how to incorporate my div into a PHP if else statement.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
"<div id='cssmenu'>
<ul>
<li>
Registration
</li>
</ul>
</div>"
}
else
{
"<div id='cssmenu'>
<ul>
<li>
<a> "Greetings " . $_SESSION['fname'] </a>
</li>
</ul>
</div>"
}
?>
The following should do the trick. As mentioned by #Ghost, you need echo and you needed to change a few quotes to single quotes.
<?PHP
session_start();
if ($_SESSION['email'] == '')
{
echo "<div id='cssmenu'>
<ul>
<li>
<a href='registration.php'> Registration</a>
</li>
</ul>
</div>";
}
else
{
echo "<div id='cssmenu'>
<ul>
<li>
Greetings " . $_SESSION['fname'] . " </a>
</li>
</ul>
</div>";
}
?>
you can use php whitin html
the php code is only considered between php tags so anything else is put directly to browser
as i can see only one part of your html changes so a better design would be
<?php session_start(); ?>
<div id="cssmenu">
<ul>
<li>
<?php if ($_Session['email']=='') {
?>
Registration
<?php }else{ ?>
Greetings -> <?php echo $_SESSION['fname']; ?>
<?php }?>
</li>
</ul>
</div>
It is possible to create an IF query for the tag in SPIP?
When i have only one article linked to the tag than he take me directly to the article. But if i have more than 1 article, than he does taken me to the tag page of spip, where are the listing of the linked article.
Here the code to go directly to the article
<div id="tagsphere-#ENV{id_article}">
<ul>
<BOUCLE_mot(MOTS){id_groupe ?}>
<B_article>
<li>
<a<BOUCLE_article(ARTICLES){id_mot = #ID_MOT}{0, 1}> href="#URL_ARTICLE"</BOUCLE_article>>
#TITRE
</a>
</li>
</B_article>
</BOUCLE_mot>
</ul>
</div>
and here the code to go to the tag menu
<div id="tagsphere-#ENV{id_article}">
<ul>
<BOUCLE_mot(MOTS){id_groupe ?}>
<li>[(#TITRE)]</li>
</BOUCLE_mot>
</ul>
</div>
Thanks in advance
Try this, will work with any SPIP version.
<BOUCLE_mot(MOTS){id_groupe ?}>
[(#REM) Link to mot]
<BOUCLE_check(ARTICLES) {id_mot} {1,1}>
<li>#_mot:TITRE</li>
[(#ID_ARTICLE|oui)]
</BOUCLE_check>
[(#REM) Link to one article]
<BOUCLE_one(ARTICLES) {id_mot} {0,1}>
<li>#_mot:TITRE</li>
</BOUCLE_one>
<//BOUCLE_check>
</BOUCLE_mot>
Conditional display is a real lack in SPIP. This is what I would do (don't have any SPIP environment with me to check).
<div id="tagsphere-#ENV{id_article}">
<ul>
<BOUCLE_mot(MOTS){id_groupe ?}>
<BOUCLE_articles(ARTICLES){id_mot = #ID_MOT}>
<B_article_unique>
<li>
<a<BOUCLE_article_unique(ARTICLES){id_article}{si #TOTAL_BOUCLE|==1}> href="#URL_ARTICLE"</BOUCLE_article_multiple>>
#TITRE
</a>
</li>
</B_article_unique>
<BOUCLE_article_multiple(ARTICLES){id_article}{si #TOTAL_BOUCLE|!=1} />
<li>
<a href="#URL_MOT">
#TITRE
</a>
</li>
</B_article_muliple>
</BOUCLE_articles>
</BOUCLE_mot>
</ul>
</div>
Below is a php issue I am having, it works in other ways but doesn't work the way I wish too.
Basically I wish to add the WP login and logout commands to the the A-HREF links, but the closing short code doesn't seem to be taken effect and I would like to know why and hopefully fix this problem.
<?php
echo do_shortcode('[not-level-visitors]') .
'<div id="SignUp">
<ul>
<li><img src="http://dev.universitycompare.com/wp-content/themes/blue-and-grey/images/icons/user_icon.png" alt="User Icon My Account University Compare" />
My Account
</li>
<li>
Log Out
</li>
</ul>
</div>' .
do_shortcode('[/not-level-visitors]');
?>
Basically the above code is kind of working, but I just need the closing shortcode to work as it appears in my html and is not being recognised - I have created the above code from this below snippet that I am already using that works completely:
<?php
echo do_shortcode('[level-visitors]
<div id="SignUp">
<ul>
<li>
Sign Up
</li>
<li>
Login
</li>
</ul>
</div>
[/level-visitors]');
?>
The main difference I spotted is the single call vs multiple calls to do_shortcode, I assume it's failing to match the regex.
Maybe this will work:
echo do_shortcode('[not-level-visitors]
<div id="SignUp">
<ul>
<li><img src="http://dev.universitycompare.com/wp-content/themes/blue-and-grey/images/icons/user_icon.png" alt="User Icon My Account University Compare" />
My Account
</li>
<li>
Log Out
</li>
</ul>
</div>[/not-level-visitors]');
It looks like you need to remove the extra opening/closing parentheses and extra do_shortcode call.
<?php
echo do_shortcode('[not-level-visitors]' .
'<div id="SignUp">
<ul>
<li><img src="http://dev.universitycompare.com/wp-content/themes/blue-and-grey/images/icons/user_icon.png" alt="User Icon My Account University Compare" />
My Account
</li>
<li>
Log Out
</li>
</ul>
</div>' .
'[/not-level-visitors]');
?>
I'm trying to build a kiosk on a local machine, so no online requirement. I am going to build a big menu which will show exhibition stores and products. Due to the stores and products will always change, the client has requested to use a simple text file - .txt to populate the menu.
I used jQuery last week but unfortunately it didn't work. So after searching I've decided to use php instead. I'm new to php, but I have given it a try today, I have only managed to populate one list with the external file kate.txt
Here is my code for the page
<body>
<ul class="sf-menu">
<li class="current">
Area1
<ul>
<li class="current">
Kate
<ul>
<?php
//variables
$dir = "C:\wamp\www\Menu";
$txtfile="Textfiles\kate.txt";
foreach (glob("$txtfile") as $filename) {
$file = $filename;
$contents = file($file);
$string = implode("<li>", $contents);
}
?>
<li><?php echo $string ?></li>
</ul>
</li>
<li>
Cathy
<ul>
<li>Banana</li>
<li>Apple</li>
</ul>
</li>
</ul>
</li>
<li>
Area2
<ul>
<li>
lily
<ul>
<li>Watermelon</li>
<li>Grapefruit</li>
</ul>
</li>
<li>
John
<ul>
<li>Orange</li>
<li>Pineapple</li>
</ul>
</li>
</ul>
</li> <!--current-->
</ul> <!--sf-menu-->
</body>
Can someone please give me some direction on the php code? I don't mind how the text files are structured in a folder, as long as I can populate all the menu list items and links with a text file or multiple text files not in the html code.
Assuming that your text file holds all your list items
kate.txt:
<li>stuff</li>
<li>stuff</li>
...
the php file
<?php
$txtfile="Textfiles\kate.txt";
$content = file_get_contents($txtfile);
<li class="current">
Kate
<ul>
<?php echo $content ?>
</ul>
</li>