Insert bootstrap module into PHP? - php

I'm trying to show a bootstrap module dialog box as a confirm delete on a database.
So the code I have:
<?php
//Sample pop up
if ($delete_category_id > 0) {
<div class="source-code runnable">
BootstrapDialog.alert('I want banana!');
</div>;
//$da->delete_category($delete_category_id);
}
?>
I've tried inserting echo's into the divs but the BootstrapDialog box doesn't work as its supposed to (or at all actually).
How can I insert this and have it work inside PHP?

There are a couple of solutions to this, one would be:
<?php if ($delete_category_id > 0) { ?>
<div class="source-code runnable">
BootstrapDialog.alert('I want banana!');
</div>
<?php } ?>
Another one would be:
<?php if ($delete_category_id > 0) {
echo <<<HTML
<div class="source-code runnable">
BootstrapDialog.alert('I want banana!');
</div>
HTML;
} ?>

Related

Detect Category ID=4 in Joomla and show div

I would like to detect a certain category with ID=4 and then apply if/else to add div to display contents.
<?php
if (JRequest::getVar('view')=='categories' && JRequest::getVar('id')==4) { ?>
<?php } ?>
How do I achieve this?
I want to show this if the article belongs to category 4 else show another div.
Imagining this two be the different div
<div class="category4">text here</div>
<div class="categoryxxx">text here</div>
Do note that <?php echo $this->item->catid;?> shows the correct Category ID. I would like to apply if and else statement using catid==9 or something. Just not good at PHP.
You can also put directly the html code, avoiding echo. It may useful especially when html code is sizeable.
<?php if ($this->item->catid == 4): ?>
<div class="category4">text here</div>
<!--- any other html code --->
<?php else: ?>
<div class="categoryxxx">text here</div>
<!--- any other html code --->
<?php endif; ?>
Hey I got it working :)
<?php
if ($this->item->catid == 9) {
echo "yes, it exists";
}
else {
echo "no, it don't exist";
}
?>

How do I excluding INDEX or Home page in PHP Code?

I know nothing about PHP. I have the code below to show next and prev at the bottom of each page, with <-|-> as a separator but I don't want it on the home/index page.
<div align="center" >
<?php echo previous_page_not_post(); ?> <-|-> <?php echo next_page_not_post(); ?>
</div>
How can I do this?
You can add an if statement like this:
<div align="center">
<?php
if (basename($_SERVER['PHP_SELF']) != "index.php") {
echo previous_page_not_post()." <-|-> ".next_page_not_post();
}
?>
</div>
(Look at get current php page name)

Replace class of a div using removeClass and addClass

For my new wordpress site I need some help. I got 4 pages and 2 different sidebars. On 2 pages there shouldn't be a border-left and on the other 2 pages there should be a border-left. So I got following code:
<div id="sidebar" class="sidebar">
<?php if(is_page('Willkommen') || is_page('Angebot'))
{
dynamic_sidebar('Angebot');
}
else
{
dynamic_sidebar('Anfahrt');
if(is_page('Anfahrt'))
{
echo "<script type='text/javascript'>
function removeBorder()
{
$(document).ready(function() {
if($('#sidebar').hasClass('sidebar'))
{
$(this).removeClass('sidebar')
$(this).addClass('secondsidebar')
}
});
}
</script>";
}
}
?>
</div><!-- sidebar -->
I want to remove the class "sidebar" and add the class "secondsidebar" if there is a div#sidebar on the page. But the code won't work. I wrote this code for myself and I'm a beginner in jQuery :) So please be patient.
I hope someone can give me a hint.
Cheers
A pure PHP solution should be possible as well.
<div id="sidebar" class="<?php if (is_page('Anfahrt')) : ?>secondsidebar<?php else : ?>sidebar<?php endif; ?>">
<?php
if (is_page('Willkommen') || is_page('Angebot')) {
dynamic_sidebar('Angebot');
}
else {
dynamic_sidebar('Anfahrt');
}
?>
</div>
NOTE: try not to use IDs and classes with the same name. #sidebar and .sidebar might get confusing.
Explanation for the classes:
<div id="sidebar" class="<?php if (is_page('Anfahrt')) : ?>secondsidebar<?php else : ?>sidebar<?php endif; ?>">
When the server reads this (PHP is code that is executed by the server before rendering the result back to the user) it comes to "class" and it notices an if-statement. "what text should I put in the class="" of this element?" The server then sees the instructions:
If the page is "Anfahrt": the text to return should be secondsidebar
Else (in all other cases): the text should be sidebar
"Text" isn't really a good name here. But you get what I mean. This "text" is then placed where the if-statement is. The result then is (as it is returned to a user):
If the page is "Anfahrt":
<div id="sidebar" class="secondsidebar">
If the page is anything else:
<div id="sidebar" class="sidebar">

jquery toggle one div in php while loop

I have this While loop in my php code where I echo rows inside one div that acts like a button and when I press that "button" I want to hide/show the connected div with the jQuery function "toggle". I only get it to work so that when I click any of the "buttons" it opens all divs and not just that one that's connected.
<script>
$(document).ready(function(){
$(".scorec").click(function(){
$(".scorematcho").slideToggle('slow');
});
});
</script>
That's the jQuery I'm using at the moment.
<?php $RM = mysql_query("SELECT * FROM score ORDER BY ScoreID DESC LIMIT 3");
while ($ScoreD = mysql_fetch_assoc($RM)) {
$a = $ScoreD["ScoreOne"]; $b = $ScoreD["ScoreTwo"];?>
<div class="scorec" >
<?php if($a>$b){;?><font color="green"><?php }else{?><font color="red"><?php }?>
<div class="scorel"><img src="flags/<?php echo $ScoreD["FlagOne"]; ?>.png" style="float:left;">
<?php echo $ScoreD["TeamOne"]; ?> | <?php echo $ScoreD["ScoreOne"]; ?></div>
<div class="scorem">-</div>
<div class="scorer"><?php echo $ScoreD["ScoreTwo"]; ?> | <?php echo $ScoreD["TeamTwo"]; ?>
<img src="flags/<?php echo $ScoreD["FlagTwo"]; ?>.png" style="float:right;"></div></font>
</div>
<div class="scorematcho" >
<div class="scorematch">
de_dust2
16-2
</div>
<div class="scorematch">
de_nuke
16-2
</div>
<div class="scorematch">
de_dust
16-2
</div>
</div>
<?PHP } session_destroy()?>
That's the HTML/PHP I'm using. The div "scorec" is the "button" and "scorematcho" is the div I wan't to toggle.The text inside "scorematcho" shall be PHP also, just haven't changed it yet. I have searched and tested some things but can't get anything to work properly, I have noticed that some put all their PHP code inside an "echo", why is that and could that be the problem? Hope that's enough information, please tell if not. Also, if you have some other improvements you think I should make to the code, please tell.
I have added this jfiddle Hope it helps!! http://jsfiddle.net/H77yf/
$(".scorec").click(function(){
$(this).next().slideToggle('slow');
});

My PHP condition statement display two results for if and else, what's wrong my my code?

I created a conditional statement for my custom theme in Concrete5. My codes goal is to toggle layout. If the current page has a child pages under it, it will display an additional sidebar (<div class="grid_3">) to list the subpages items. If there's no child page it would display a full layout (<div class="grid_13">).
Unfortunately I get a different result. there's something I probably had missed on my condition statement. Instead of just display one layout, It is rendering the two layout.
Below is what my code look like:
<? if($c->getNumChildren()) { ?>
<div class="grid_3">
<?php
$bt_sidenav = BlockType::getByHandle('autonav');
$bt_sidenav->controller->orderBy = 'display_asc';
$bt_sidenav->controller->displayPages = 'below';
$bt_sidenav->controller->displaySubPages = 'all';
$bt_sidenav->render('view');
?>
</div>
<div id="main-content-container" class="grid_10">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } else { ?>
<div id="main-content-container" class="grid_13">
<div id="main-content-inner">
<?php
$a = new Area('Main');
$a->display($c);
?>
</div>
</div>
<? } ?>
While your content generation portions of PHP use proper PHP tags (<?php … ?>), your if/else statements use short tags (<? … ?>) which are often disabled.
Use <?php instead.
try to do like this may this will solve the issue
<?php if($c->getNumChildren()!='') { ?>
...
<?php } else { ?>
...
<?php } ?>

Categories