I want to generate the following code automatically within a Wordpress loop:
<ul class="content">
<li class="box it" data-id="id-1" data-type="it">
<h1>No# 01</h1>
</li>
<li class="box medical" data-id="id-2" data-type="medical">
<h1>No# 02</h1>
</li>
<li class="box education" data-id="id-3" data-type="education">
<h1>No# 03</h1>
</li>
</ul>
What I want it to have my php code from within the Wordpress loop to echo "data-id="+(auto incremented number as in the above instance).
How will I construct the loop?
try
<ul class="content">
<?php for($i=1;$i<some_num;$i++) {?>
<li class="box it" data-id="id-<?php echo $i; ?>" data-type="it">
<h1>No# <?php echo $i; ?></h1>
</li>
<?php } ?>
</ul>
Related
I am creating a module for Question and Answers and I need to fetch the data separatedly each.
I created a Tab where I'll click the Question I want to answers, and its children or the answer should match.
For visual reference, here is my problem
I have this data that are all fetched, which should not be. That is why I created Tabs and Pills so I can separate questions and answers
12 and 13 are the id number of each data
So in Tabs and Pills, I got this
The problem of this, is that I cannot fetch the data dynamically, it just shows ID 13 data for question and answer. How can I change this dynamically so I can click back and forth the tabs and show the right data by its id?
I need to fetch the ID 12 of the 1st Tab
So here is my view
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<?php echo $question->id; ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="13" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<?php if($answer->type_id==0): ?>
<input type="radio" name="question_<?php echo $question->id; ?>" value="<?php echo $answer->answer ?>" required/>
<?php echo $answer->answer; ?><hr>
<?php endif; ?>
<?php if($answer->type_id==1): ?>
<div class="input-group input-group-lg">
<input type="text" class="form-control col-md-6" placeholder="Enter Answer" name="question_<?php echo $question->id; ?>" required/>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div><br>
</div>
</div>
Fix the tabs structure, your looping over questions for nav-item, but not looping over for tab-pane which is why clicking the tab link does nothing.
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php foreach($questions as $question){ ?>
<div class="tab-pane" id="tab-<?= $question->id ?>" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<!-- form input $answer / item -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>
while($recor1=mysql_fetch_assoc($res1))
{
?>
<ul>
<li class="col-md-3 col-sm-3"><div class="dest-list"><?php echo $recor1['sub_destination']; ?></div> </li>
</ul>
<div class="clearfix"></div>
<?php
}
it displays the result horizontally i want it vertically please give me soluation
there are a number of things wrong with your code, why are you adding a new list for every item with only one list item, that makes no sense. Also do not add block elements inside inline elements (div inside a). Also if you what the list items under each other then why add the col-... class?
<ul>
<?php while($recor1=mysql_fetch_assoc($res1)) {?>
<li class="">
<a href="#">
<?php echo $recor1['sub_destination']; ?>
</a>
</li>
<?php } ?>
</ul>
this gives you the right html structure, and you can then style it as you see fit
if you dont want to display a list horizontally remove col-sm-3 class of your li, which changes your code like below
while($recor1=mysql_fetch_assoc($res1)) { ?>
<div class="col-md-3 col-sm-3">
<ul>
<li >
<a href="#">
<div class="dest-list">
<?php echo $recor1['sub_destination']; ?>
</div>
</a>
</li>
</ul>
</div>
<div class="clearfix"></div>
<?php
}
take a look at this example
I want to display slide with two records at a time. Now I am only getting only one record at a time in slider because I fetch data in while loop. My code is:
<ul class="slides">
<?php
...
while($eventData = mysql_fetch_array($eventSql))
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>
</ul>
You can add a counter and open/close the list item only every second iteration:
<ul class="slides">
<li class="questions-slide-item">
<?php
...
$count = 0;
while($eventData = mysql_fetch_array($eventSql))
{
if($count > 0 && $count % 2 == 0) {
?>
</li>
<li class="questions-slide-item">
<?php
}
?>
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
<?php
$count++;
}
?>
</li>
</ul>
You can first take all the rows in one array and then use that array as per your needs.
See to following code to understand what I am trying to say.
<?php
...
$eventData= array();
while($row = mysql_fetch_assoc($eventSql))
{
$eventData [] = $row;
}
for($i=0;count($eventData);$i=$i+2)
{
?>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<li class="questions-slide-item">
<div class="query clearfix">
<div class="image fl">
<img src='<?php echo $eventData[$i+1]['image']; ?>' style="width:63px; height:61px;">
</div>
</div>
</li>
<?php } ?>
I am new to codeigniter, From My senior i got one task to solve existing undone internal project. and develop that project again.
i am having query when i am ruinning this project.
here i am pasting my 2 view files.
tell me if any one required further files.
Thank you in advanced.
TODO DropDown View
<!-- BEGIN TODO DROPDOWN -->
<?php
if (isset($pendingtask)) {
?>
<li class="dropdown" id="header_task_bar">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
<i class="icon-tasks"></i>
<span class="badge"><?php echo count($pendingtask); ?></span>
</a>
<ul class="dropdown-menu extended tasks">
<li>
<p>You have <?php echo count($pendingtask); ?> pending tasks</p>
</li>
<li>
<ul class="dropdown-menu-list scroller" style="height:250px">
<?php
if (!empty($pendingtask)) {
foreach ($pendingtask as $task_row) {
?>
<li>
<a href="<?php echo base_url(); ?>milestone/viewMilestone/<?php echo $task_row->id; ?>">
<span class="task">
<span class="desc"><?php echo $task_row->title; ?></span>
<span class="percent">30%</span>
</span>
<span class="progress progress-success ">
<span style="width: 30%;" class="bar"></span>
</span>
</a>
</li>
<?php
}
}
?>
</ul>
</li>
<li class="external">
See all tasks <i class="m-icon-swapright"></i>
</li>
</ul>
</li>
<!-- END TODO DROPDOWN -->
<?php } ?>
pagetopnavigation view
<!-- BEGIN HEADER -->
<div class="header navbar navbar-inverse navbar-fixed-top">
<!-- BEGIN TOP NAVIGATION BAR -->
<div class="navbar-inner">
<div class="container-fluid">
<?php $this->load->view('include/pagelogo'); ?>
<!-- BEGIN TOP NAVIGATION MENU -->
<ul class="nav pull-right">
<?php //$this->load->view('include/pagetopnotifications'); ?>
<?php //$this->load->view('include/pagetopnewmessage'); ?>
<?php $this->load->view('include/pagetoptodo', $pendingtask); ?>
<?php $this->load->view('include/pagetopuserprofile'); ?>
</ul>
<!-- END TOP NAVIGATION MENU -->
</div>
</div>
<!-- END TOP NAVIGATION BAR -->
</div>
<!-- END HEADER -->
?php $this->load->view('include/pagetoptodo', $pendingtask); ?>
is where your error is: the second parameter needs to be an array. So:
?php $this->load->view('include/pagetoptodo', array('pendingtask'=>$pendingtask)); ?>
in order to pass to a sub-view
In Your pagetopnavigation view page you used the variable "$pendingtask"
(<?php $this->load->view('include/pagetoptodo', $pendingtask); ?>)
The error what you are getting is a Notice => it is saying the variable($pendingtask) is not defined in your code ; it will not stop the execution of file, you can stop "Notice and Warning" messages by using error_reporting method or you can set up this in Codeigniter configurations, check this link for reference : http://phpdog.blogspot.in/2012/02/codeigniter-error-reporting-handling.html
I'm using custom fields and would like to add an image to every third slide.. How do you do this.. could it possibly be done with jQuery and how?? So new to this
<div class="flexslider">
<ul class="slides slide-ul">
<?php while(the_repeater_field('text_scroll')): ?>
<li class="slide">
<span class="scroll-text1 slider"><?php the_sub_field('scroll_top_text');?></span>
<span class="scroll-text2 slider"><?php the_sub_field('scroll_bottom_text');?></span>
</li>
<?php endwhile; ?>
</ul>
</div>
Use nth child selector
DEMO
$('.slide:nth-child(3n)').append('<img src="IMage.jpg" />');
Using normal PHP
<div class="flexslider">
<ul class="slides slide-ul">
<?php $i=0 ; while(the_repeater_field( 'text_scroll')):
if($i % 3===0 ){echo '<li>each 3rd row this row will display</li>';} ?>
<li class="slide">
<span class="scroll-text1 slider">
<?php the_sub_field('scroll_top_text');?>
</span>
<span class="scroll-text2 slider">
<?php the_sub_field('scroll_bottom_text');?>
</span>
</li>
<?php $i++; endwhile; ?>
</ul>
</div>