I am trying to display specific text at the bottom of a menu but I only want this text to show if I am looking at a certain menu. This is the code I have:
<?php get_post_type( $post ) ?>
<?php if ( $post->post_name === 'belden-village' ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank You</p>"; ?>
<?php endif ?>
This code works in staging but as soon as we moved the site live it no longer displays the text when it is supposed to. I am calling it by the "slug" and the slug is the same in both staging and live site. Any ideas why this has suddenly stopped working? This is my first experience taking a site live so any help would be greatly appreciated. Thanks.
Why not use the is_single() function?
<?php get_post_type( $post ) ?>
<?php if ( is_single( 'belden-village') ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
You</p>"; ?>
<?php endif ?>
If you are looking for a page instead of a post you can use the is_page() function instead:
<?php get_post_type( $post ) ?>
<?php if ( is_page( 'belden-village') ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
You</p>"; ?>
<?php endif ?>
Related
I have an ACF true or false based if the condition to show a section based on the mentioned code. it works correctly on the front page/homepage of WordPress. but it doesn't work in the inner pages, not getting the values of the field and I use this code in footer templates.
its a WordPress site with the latest version. and the code is in the footer template
<?php
$show_company_info = get_field( "show_company_info", get_the_ID() );
if($show_company_info ):
?>
<section class="company">
<div class="container">
<?php if ( is_active_sidebar( 'company-info-widget' ) ) : ?>
<?php dynamic_sidebar( 'company-info-widget' ); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
if we checked the ACF true/fields condition in any page it will show the section otherwise not. but it actually works in homepage only
Assuming that you have created a field in a Home Page.
So, to retrieve the home page field you need to do like this :
$frontpage_id = get_option( 'page_on_front' );
$show_company_info = get_field( "show_company_info", $frontpage_id );
if ( $show_company_info ) {
//Your code
}
I need to display HTML code to all user roles except "subscriber" in wordpress.
Here is code that I can't get working.
<?php
$current_user = wp_get_current_user();
?>
<?php if ( $current_user->role == 'subscriber' ) : ?>
<span>here is my html</span>
<?php endif; ?>
PS
I'm not that good with php as you can tell.
Solved! I used following code that gives desired functionality:
<?php if ( $this->current_user_can_edit_posts ) : ?>
<span>my html</span>
<?php endif; ?>
For others, you might need to change "$this" part. So you can retrieve current_user. Maybe someone can still post an answer for them.
Tried and tested code that works. Let me know if it works for you too! :)
<?php
$current_user = wp_get_current_user();
if ( ! in_array( 'subscriber', (array) $current_user->roles ) ) {
?>
<span>here is my html</span>
<?php
}
?>
Can anyone guide me trow the files that need to update in order to get
no result found
on search redirect to other page or different text (like leading into fill form)?
I am using wp woocomerce and woof search plug in. I found on the search.php that gives me a hit.
</div>
<?php graphene_posts_nav(); ?>
<?php else : ?>
<?php get_template_part( 'loop', 'not-found' ); ?>
<?php endif;
}
Yes you need to use the if else condition based on the found posts like below.
<?php if ( have_posts() ) : ?>
//display search template
<?php else : ?>
//display no results template
<?php get_template_part( 'no-results', 'search' ); ?>
<?php endif; ?>
In this case no results template will be no-results-search.php
I'm looking for a possibility to add a custom html block/post to the woocommerce "shop page" inside the products grid, as a product.
What I mean.. I have a grid of products on the "shop" page (archive-product) and I want to create a special post/page/html block with some text information, that will be inserted into the products grid as a one of "product", but with no price, with no title and unclickable. I've attached the screenshot of the final result I want to have, it's really self explaining - here it is exactly what I'm looking for.
As an idea probably I can create a special product with specific slug or title and the corresponding script with pre_get_posts hook will find this post/product and modify it to look like I need. I'm looking for some code/ideas how to insert this specific block/page/post into the archive-product page on some position in the grid. Thanks!
Thanks for help, guys! I've implemented the functionality I was looking for. I've found the corresponding loop in archive-product.php and as was suggested by JapanGuy, I've added a simple "if i equal let's say 5 then echo < li>[Custom block]< /li>" .
The original snippet from archive-product.php:
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
Modified code with inserted custom block:
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ($i == 5) {
echo "<li>[Custom block]</li>";
}
$i++;
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
Im such simple way I can add any content to the created [Custom block] and have an usual products grid with extra custom designed block. I'm not very experienced programmer, so probably my code is not perfect, but it works. Thanks!
Edit: Previous code was wrong, changed it here
$i=0;
while ($row = mysqli_fetch_array($query))
{
if ($i == 2) {
echo "Cusom block";
}
echo "<p> Product block " . $row['column'] . " </p>";
$i++;
}
Creating WordPress Custom Post Archives : Hope this meets your requirement.
Custom Post Archives list your custom content. You probably already know the standard WordPress archives. So you can follow this to display both together .
Ref here : https://wp-types.com/documentation/user-guides/creating-wordpress-custom-post-archives/
I'm a bit new to this, but I researched this topic a bit online and can't seem to figure out what I'm doing wrong. So basically, I created a duplicate footer to call for the homepage. We use a marketing automation tool called Pardot and we don't want to track visits to the homepage. So I created a file in the footer folder next to "footer-default.php" called "footer-nopardot.php" that omits the code.
In the home.php file, I edit the bottom with
<?php
get_footer('nopardot'); ?>
But it appears the homepage is still calling the default footer. Any advice on what to do or what I'm doing wrong?
Thanks!
just add this to your home template:
<?php
if ( is_home() ) :
get_footer( 'nopardot' );
else :
get_footer();
endif;
?>
you can use this loop just replace the home or 404 by your page name where you want to display your footer:
<?php
if ( is_home() ) :
get_footer( 'home' );
elseif ( is_404() ) :
get_footer( '404' );
else :
get_footer();
endif;
?>
and since you are just changing your home page footer u can just do this
<?php
if ( is_home() ) :
get_footer( 'yourName' );
else :
get_footer();
endif;
?>
Make sure of the file name to be footer-yourName.php
and then call it as follow:
get_footer( 'yourName' );
hope that helps :)