jQuery or markup? - php

I've successfully gotten my menu to be sticky using jQuery waypoints in this jsFiddle. It works fine in the fiddle, but when I implement on my test drupal site, it's no longer active.
Here's the markup:
<?php if ($page['main_menu']): ?>
<div id="stickywrapper">
<div class="main-menu-wrapper">
<div class="main-menu-wrapper-inner <?php echo $grid_size ?>">
<nav id="main-menu" class="<?php echo $grid_full_width ?> clearfix">
<?php print render($page['search_box']); ?>
<?php print render($page['main_menu']); ?>
</nav>
</div><!--end main-menu-wrapper-inner-->
</div><!--end main-menu-wrapper-->
</div><!--end stickywrapper-->
<?php endif; ?>

You've got a stray Unicode zero width space (U+200B) character at the end of the JavaScript code in stickymenu.js, causing a syntax error. Delete that and it all works out.

Related

PHP echo not outputting html tags

I'm trying to output content from an Advanced Custom Fields (ACF) in my wordpress theme. At the moment though, all I'm getting is the plain text content from the ACF inside double quotation marks, not inside the div and h1 tags.
The code is copied from another theme I made where it worked, which makes me think something is interfering with it somewhere?
<?php $process_title = the_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>
Thanks to #M.Eriksson, the correct code should be:
<?php $process_title = get_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>

Show banner only on archive pages using PHP

I have a banner I would like to only show on archive pages on my website. I can't figure out the php code to do so. Here is what I have so far (obviously I've removed a lot of the code to make this look cleaner and easier):
<header id="masthead" class="site-header navbar-static-top fixed-top <?php echo wp_bootstrap_starter_bg_class(); ?>" role="banner">
</header>
<?php if(is_archive()) ?>
<div class="free-shipping-banner">
<p>
FREE SHIPPING on all print orders within North America.
</p>
</div>
<?php endif; ?>
You can see it is my free-shipping-banner that I want only displayed on archive pages. I'm not getting any errors with this code, but it's still showing up on all other pages of my website. Does anyone know what I am doing wrong?
Here is your correct code. Please add brackets for if statement.
<header id="masthead" class="site-header navbar-static-top fixed-top <?php echo wp_bootstrap_starter_bg_class(); ?>" role="banner">
</header>
<?php if(is_archive()) { ?>
<div class="free-shipping-banner">
<p>
FREE SHIPPING on all print orders within North America.
</p>
</div>
<?php } ?>
The mistake in your code is that the if statement will only look for the next line. But when you place brackets; you tell the server where it ends. You used endif but you also forgot a colon at the end of if statement. The above code will work.

add images to slider in php. My code just adds one image

my code only shows one image from the database. I dont know whats the problem. I tried looping it with allthe divs and ul but nothing it only shows one image. my code is
<div class="fullwidthbanner-container">
<div class="fullwidthbanner">
<?php
$about = slider();
while($about_fetch=mysql_fetch_array($about)){
?>
<ul>
<li data-transition="fade" data-slotamount="7">
<img src="images/<?php echo $about_fetch["slide"];?>" alt="">
<?php
}?>
</li>
</ul>
<!--<div class="tp-bannertimer"></div>-->
</div><!-- end .banner -->
</div><!-- end .bannercontainer -->
for the code-part, try this please:
(i assume, you dont want to have several <ul> elements and only the <li>'s)
<div class="fullwidthbanner-container">
<div class="fullwidthbanner">
<ul>
<?php
$about = slider();
while($about_fetch=mysql_fetch_array($about)){ ?>
<li data-transition="fade" data-slotamount="7">
<img src="images/<?php echo $about_fetch["slide"];?>" alt="">
</li>
<?php } ?>
</ul>
</div><!-- end .fullwidthbanner -->
</div><!-- end .fullwidthbanner-container -->
Well, your HTML isn't valid. You're looping over the start of a <ul> and <li> and not closing either until after the loop.
If that isn't the problem, then we can't help you since there is no debugging information available. Break your problem up into pieces. Is the issue server-side or client-side? Look at your output HTML to be sure. What are the return values of mysql_fetch_array() for each iteration? var_dump() is your friend.

Magento Static Block is at a Different Place on Internet Explorer than on Chrome, Firefox

I created 3 static blocks ('vert_nav_link', 'social_network', and 'vert_goto_hapi') on a magento site and placed them on the left column (sidebar). On Chrome, Firefox and Safari, they are all shown on the left sidebar. On IE 8, the last static block ends up at the main column. Not sure why, since I used the same coding on all three. Here is the php code,
<div class="main-container col2-left-layout">
<div class="main">
<div class="col-main">
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-left sidebar">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('vert_nav_link')->toHtml(); ?>
<?php echo $this->getChildHtml('left') ?>
<?php echo $this->getChildHtml('right') ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('social_network')->toHtml(); ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('vert_goto_hapi')->toHtml(); ?>
</div>
</div>
</div>
Any insight will be helpful.
Thank you
Check those:
*HTML for last block is valid. Means there are no such things like:
<span</span>
*Change the left block height. It might be simply css problem. So try to increase left block height and might be put float left on this block, but I am not sure, because I am not CSS guru. Also display:inline-block or inline might solve your problem.

Drupal Block PHP

Im created a custom block, with the below code, but im having some trouble turning the Group Title into an link, that will take the user back to the group at anytime.
Below is the code ive used, I thought active turns it into a link, but perhaps im being stupid.
<div class="active"><h2><?php print $group_title; ?></h2></div>
Below is the full code:
<?php $group_title = og_get_group_context()->title; ?>
<?php $group_nid = og_get_group_context()->nid; ?>
<?php $forum_link = og_forum_get_forum_container($group_nid); ?>
<div class="active"><h2><?php print $group_title; ?></h2></div>
<div class="content"
<div class="item-list">
<ul>
<li class="user-input-link"><a title="Add a new Forum topic"href="/node/add/forum?gids[]=<?php print $group_nid; ?>">Add a new forum topic</a>
</ul>
</div>
</div>
You need to create URL for it to work.
Here is the link to API with more info: http://api.drupal.org/api/drupal/includes--common.inc/function/l/6
<div class="active"><h2><?php print l($group_title, "node/{$group_nid}"); ?></h2></div>
You need to do an anchor tag, like:
<div><h2><?php print $group_title; ?></h2></div>
I don't know how to get the url in Drupal though..

Categories