Show banner only on archive pages using PHP - 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.

Related

Hide section if there is no featured image

I made a custom template for the team I'm working on. I used this code for the template (along with the parts that get the header and footer ofc)
<div class="main-container">
<?php
the_post();
$thumbnail = has_post_thumbnail();
?>
<section class="section-header overlay preserve3d">
<div class="background-image-holder parallax-background">
<?php the_post_thumbnail('full', array('class' => 'background-image')); ?>
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="article-body">
<?php
if(!( $thumbnail ))
the_title('<h1>','</h1>');
the_content();
wp_link_pages();
?>
</div><!--end of article snippet-->
</div>
</div>
</div>
</section>
But if there's no featured image, a gray box will appear. I'd rather just have the whole section be hidden if there is no featured image, because it will look much better.
I'm a php rookie so I have no idea how to do this. What I think I need to do: Have an if/else statement check for the featured image. If there is no image, add a class to said section and define 'display none' in my css file for that class.
So this is the code I tried to pair with that, but it did not work:
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
$("section:first").addClass("noshow");
}
?>
Is this code incorrect? Where do I need to place this in my document for it to work?
While PHP is executed on the server, jquery is executed on the user end. You could always echo that jquery statement and that way it would be sent to the user.
You could follow the path Martin E. said on his comment (which in my opinion is a much cleaner version) or you could pursue the way you were working on by adding jquery on your header if you haven't and trying something like this:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<script>$("section:first").addClass("noshow");</script>';
}
?>

Drupal - Views - Taxonomy Term ID - custom template - anchors

Quick version: How do I output a taxonomy term ID in a views template? I just want the numeric ID value. This will be used as a link anchor.
Long version:
Scenario, I have a view which displays a list of taxonomy terms. That view has a Page and a Block. The Page view is set to display the Block view as a header. That Block view simply contains the taxonomy names. The Page view displays all of the taxonomy content.
I want the Block view list to anchor to the items in the Page view:
This view is already built, the missing part of the equation is getting the anchor links in place.
The view currently comprises 3 custom template files:
views-view-fields--categories--page.tpl.php
<article id="NEED THE TERM ID HERE">
<header>
<h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
</header>
<div class="table">
<div class="table-cell">
<?php print $fields['field_category_image']->content; ?>
</div>
<div class="table-cell">
<?php print $fields['description']->content; ?>
</div>
</div>
</article>
views-view-fields--categories--block.tpl.php
<li><?php print $fields['name']->content; ?></li>
views-view--categories--block.tpl.php
<ul>
<?php print $rows; ?>
</ul>
I've tried using a views contextual filter rewrite on the top block view links, with no luck.
All I need is the variable for the TERM ID - I've done a var dump of the available variables, I can see the TID in that list, but have no idea how to reference it in a views-view-fields template file and can find nothing online that answers this most simple of concepts.
Screenshots of the Page and Block view setup:
Finally won my argument that this jump list is completely redundant and stupid, so it'll be removed, however, I did manage to output the TID, which was fairly obvious, as these things often are...
views-view-fields--categories--block.tpl.php
<li>
<?php print $fields['name']->content; ?>
</li>
views-view-fields--categories--page.tpl.php
<article id="cat<?php print($view->result[$view->row_index]->tid); ?>">
<header>
<h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
</header>
<div class="table">
<div class="table-cell">
<?php print $fields['field_category_image']->content; ?>
</div>
<div class="table-cell">
<?php print $fields['description']->content; ?>
</div>
</div>
</article>
The variable is obviously in the view array, it was just a case of getting the index of the current view item.
Adding
<?php print $fields['tid']->content; ?>
should give you the TID in views-view-fields--xxx--page.tpl.php and --block.tpl.php
Make sure the fields are set to remove any default wrappers and you should be good to go.

Full Width colour sections but not full width page content

I am using Bootstrap but under the roots.io wordpress template using a 'wrapperless theme'
i am trying to achieve this http://roots.io/ - where there are sections of colour but the page content itself isn't full width.
the answer I have been given is to make the container class 100% - but this just makes all the content full width.
Im really stuck and ive been trying to figure this out for hours. - I know that sounds noobish and it is, but I can't get past this point.
all the page templates take their its style from base.php, code here
<?php get_template_part('templates/head'); ?>
<body <?php body_class(); ?>>
<!--[if lt IE 8]><div class="alert alert-warning"><?php _e('You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.', 'roots'); ?></div><![endif]-->
<?php
do_action('get_header');
// Use Bootstrap's navbar if enabled in config.php
if (current_theme_supports('bootstrap-top-navbar')) {
get_template_part('templates/header-top-navbar');
} else {
get_template_part('templates/header');
}
?>
<div class="wrap container" role="document">
<div class="content row">
<div class="main <?php echo roots_main_class(); ?>" role="main">
<?php include roots_template_path(); ?>
</div><!-- /.main -->
<?php if (roots_display_sidebar()) : ?>
<aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
<?php include roots_sidebar_path(); ?>
</aside><!-- /.sidebar -->
<?php endif; ?>
</div><!-- /.content -->
</div><!-- /.wrap -->
<?php get_template_part('templates/footer'); ?>
</body>
</html>
so Im just not sure how to get past it in any of the page templates
About the first part of your question: "100% width colored parts".
Cause Bootstrap use the box-sizing: border-box model every html-element gets 100% width of its parent by default. So wrap your .container div's in other element (div, header, etc). This wrapper is a direct child of the body and gets 100% width. See: http://bootply.com/87196
<header role="banner" class="banner">
<div class="container" style="background-color:red;">
Header example
</div>
</header>
<div style="background-color:blue;">Elements get 100% width by default</div>
The second part about your page templates. The code you show use the get_template_part(). This function is a core function of WordPress. See http://codex.wordpress.org/Function_Reference/get_template_part#Using_loop.php_in_child_themes. You will find where your templates should be located.
But i think read http://roots.io/roots-101/#theme-templates first.
Thank you, I had a few solutions offered to me yesterday also, in case anyone else looks at this.
my own was simply to remove the .container class from the base.php file. - this just stopped the content of every page being constrained in a container by default. - this way I was able to add sections to the page at full browser width, and add .container inside them to constrain the actual content.
lines 16 and 17 of original base.php
<div class="wrap <?php if ( ! is_front_page() ): ?>container<?php endif; ?>" role="document">
<div class="content <?php if ( ! is_front_page() ): ?>row<?php endif; ?>">
In app.less
.home .main {
padding: 0;
}
Then add your sections like so:
<section class="semantic-section-class">
<div class="container">
<!-- your content -->
</div>
</section>

jQuery or markup?

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.

Magento - cart not showing and checkout/cart page empty (doesn't show the .cart div)

Okay, so I'm a newbie to Magento and have been making lots of changes to get it working the way a client is wanting.
Obviously at install and early on, the shopping cart was working fine. I moved it up to the top right corner for a while w/ CSS and then I THOUGHT that I display:none'd it, as I just wanted to focus on other things for a while before moving on to styling it. Now I've done all those other things and want to deal with the cart. Trouble is - it is nowhere to be found and the display:none that I thought I'd used to turn it off is similarly missing. Maybe I never did it?
I can't find anything in the CSS that would have turned off the cart - I can't find a display:none on it or any parents. Most of the site is using a 2 column with left sidebar layout, and I know the shopping cart resides by default in the right. But when I turn back on the right sidebar - no cart. Furthermore, when I go to add a product to the cart, I am redirected to mydomain.com/checkout/cart as expected, but there is nothing on the page. My styling, menus, etc are present but the .col-main element where the full-page detailed cart should be is empty. Which makes me think again that the problem isn't CSS.
It's as if the site just isn't calling for the cart (I assume cart.phtml?). It is totally possible that I screwed something up while messing with other things (adding a CMS page menu at top, lots to do with resizing images, moving the category menu to the left sidebar). My php isn't good enough to find the culprit and I'm not even sure which file I should be looking at - checkout.phtml?
I realize this question has very little valuable information, but does anyone have any ideas as to where I should be looking? I can post the relevant code if I know which file to look in. The site is cart.oldfloridian.com. If you want to try to add a product, there is only one at the moment, at "ak starfish --> starfish women's"
Edit: so the /checkout/cart page is a 3column layout. Here is the 3columns.phtml code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<div id="cms-menu">
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()
->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route') { ?>
<li>
<?php echo $PageData['title'] ?>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col3-layout">
<div class="main">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="col-wrapper">
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>
There does seem to be a bug in there somewhere - we had a similar issue where two devs in the team couldnt see the cart, 1 could - but it wasnt just the cart it was the whole customer section (login, cart, my account etc).
We tried enabling Template Path Hints but the only thing in the main section of the page was "frontend/default/default/template/catalog/msrp/popup.phtml". We re-installed most of magento - no luck
We tried pretty much everything and what fixed it was coping all of the theme files into a new theme and re-naming it. Only thing I can think of that it could have been was a hyphen in the theme name

Categories