Here is a piece of my code.
<div class="thim-course-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="lpr_course <?php echo 'course-grid-' . $columns; ?>">
**<div class="course-item" onmouseover="hide_card('<?= get_the_ID()?>');" onmouseout="show_card('<?= get_the_ID()?>');">**
<div class="course-thumbnail" id="course-thumbnail-<?= get_the_ID()?>">
<a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
<?php echo thim_get_feature_image( get_post_thumbnail_id( get_the_ID() ), 'full', $thumb_w, $thumb_h, get_the_title() ); ?>
</a>
<?php do_action( 'thim_inner_thumbnail_course' ); ?>
<!-- <a class="course-readmore"
href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html__( 'Read More', 'eduma' ); ?></a> -->
</div>
<div class="thim-course-content" id="thim-course-content-<?= get_the_ID()?>">
<?php learn_press_courses_loop_item_instructor();
the_title( sprintf( '<h2 class="course-title">', esc_url( get_permalink() ) ), '</h2>' );
?>
<?php if ( class_exists( 'LP_Addon_Coming_Soon_Courses_Preload' ) && learn_press_is_coming_soon( get_the_ID() ) ): ?>
<div class="message message-warning learn-press-message coming-soon-message">
<?php esc_html_e( 'Coming soon', 'eduma' ) ?>
</div>
<?php else: ?>
<div class="course-meta">
<?php learn_press_courses_loop_item_instructor(); ?>
<?php thim_course_ratings(); ?>
<?php learn_press_courses_loop_item_students(); ?>
<?php thim_course_ratings_count(); ?>
<?php learn_press_courses_loop_item_price(); ?>
</div>
<?php learn_press_courses_loop_item_price(); ?>
<?php endif; ?>
<div class="course-readmore">
<?php esc_html_e( 'Read More', 'eduma' ); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
On the 4th line, I wanted to truncate the course maps on mouse over, so that all the part of the map at the bottom of the image disappears, only to reappear when there is no more flyover. The result obtained is different from what I wanted.
I put the link to the site to see: www.formatine.com
And here is the JS part that I added as well.
function hide_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'none';
document.getElementById('course-thumbnail-'+id).innerHTML = "<?= wp_oembed_get( $media_intro ) ?>";
}
function show_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'block';
document.getElementById('course-thumbnail-'+id).style.display = 'block';
}
Do you have an idea for me please? Thank you.
Don't use "display: none" because once it has it, the element "disappears".
It is better for you, to then, if you want to include a video instead of the card, for example, do it by having both, one behind the other by default, if you "mouseover" display the code INSIDE of one, and on "mouseout", display the other.
<div class="mycard">
<div class="myinfoforthevideo"></div>
<div class="myvideo"></div>
</div>
You controll the events on mycard class, and hide myinfoforthevideo by default, on "mouseover", hide it and show then myvideo, and on "mouseout" hide myvideo and show myinfoforthevideo
You're hidding everything so now since its a width: 0/height: 0 let's say, you don't have any place to do the mouseover now.
Extra:
You can try flip cards as another option, like this:
https://codepen.io/Aoyue/pen/pLJqgE
Related
I am using Advanced Custom Fields and Facet WP.
Currently there is a directory listing showing on a page that shows a business preview by displaying a business title, image and an excerpt - the same as you typically see from a post archive page.
I have added a new ACF checkbox field 'Are you ready to publish' and would like to amend the php so the Title, excerpt an image will only show for user profile listings that have checked 'yes' to publish.
I am fairly new to php and ACF and cannot get it to work.
I have tried to variations:
<?php
global $post;
?>
<div class="business-directory-results">
<?php if( get_field('ready_to_publish') == 'yes' ) { ?>
<?php while ( have_posts() ): the_post(); ?>
<a class="business-directory-result box-shadow" href="/member-profile/<?php the_field('user_login');?>/">
<img src="<?php echo wp_get_attachment_image_src(get_post_meta( $post->ID, 'meta-business_featured_image', true ), "full")[0];?>" />
<div class="business-directory-result-content">
<h2><?php the_field('meta-business_name');?></h2>
<?php $excerpt = wp_trim_words( get_field('meta-business_profile_content' ), $num_words = 25, $more = '...' ); ?>
<p><?php echo $excerpt; ?></p>
</div>
</a>
<?php endwhile; ?>
<?php else { ?>
<!-- do nothing -->
<?php } ?>
</div>
and
<?php
global $post;
?>
<div class="business-directory-results">
<?php while ( have_posts() ): the_post(); ?>
<?php if( get_field('ready_to_publish') == 'yes' ) { ?>
<a class="business-directory-result box-shadow" href="/member-profile/<?php the_field('user_login');?>/">
<img src="<?php echo wp_get_attachment_image_src(get_post_meta( $post->ID, 'meta-business_featured_image', true ), "full")[0];?>" />
<div class="business-directory-result-content">
<h2><?php the_field('meta-business_name');?></h2>
<?php $excerpt = wp_trim_words( get_field('meta-business_profile_content' ), $num_words = 25, $more = '...' ); ?>
<p><?php echo $excerpt; ?></p>
</div>
</a>
<?php else { ?>
<!-- do nothing -->
<?php } ?>
<?php endwhile; ?>
</div>
If you create posts first and then add an additional ACF field, they will not work. To make it work, you will need to update all your posts after adding an ACF field. In your case, you will need update each user profile and only then they will have the ACF field attached with them.
Don't place the condition outside of the loop. That means your second variation is correct.
<?php
global $post;
?>
<div class="business-directory-results">
<?php while ( have_posts() ): the_post(); ?>
<?php if( get_field('ready_to_publish') == 'yes' ) { ?>
<a class="business-directory-result box-shadow" href="/member-profile/<?php the_field('user_login');?>/">
<img src="<?php echo wp_get_attachment_image_src(get_post_meta( $post->ID, 'meta-business_featured_image', true ), "full")[0];?>" />
<div class="business-directory-result-content">
<h2><?php the_field('meta-business_name');?></h2>
<?php $excerpt = wp_trim_words( get_field('meta-business_profile_content' ), $num_words = 25, $more = '...' ); ?>
<p><?php echo $excerpt; ?></p>
</div>
</a>
<?php else { ?>
<!-- do nothing -->
<?php } ?>
<?php endwhile; ?>
</div>
I created a shortcode to display social icons within the theme I am using (Divi). The social icons are contained in a PHP template called "social_icons.php".
This is the function I am using:
function social_icons_shortcode() {
$social_icons = get_template_part( 'includes/social_icons' );
echo $social_icons;
}
add_shortcode('social-icons', 'social_icons_shortcode');
Here is the the social_icons.php template:
<div id="custom-social-icons">
<?php if( get_field('facebook', 'option') ): ?>
<a class="icon facebook" href="<?php echo get_field( 'facebook', 'option' ) ?>" title="Follow us on Facebook"></a>
<?php endif; ?>
<?php if( get_field('twitter', 'option') ): ?>
<a class="icon twitter" href="<?php echo get_field( 'twitter', 'option' ) ?>" title="Follow us on Twitter"></a>
<?php endif; ?>
<?php if( get_field('instagram', 'option') ): ?>
<a class="icon instagram" href="<?php echo get_field( 'instagram', 'option' ) ?>" title="Follow us on Instagram"></a>
<?php endif; ?>
<?php if( get_field('youtube', 'option') ): ?>
<a class="icon youtube" href="<?php echo get_field( 'youtube', 'option' ) ?>" title="Follow us on YouTube"></a>
<?php endif; ?>
<?php if( get_field('linkedin', 'option') ): ?>
<a class="icon linkedin" href="<?php echo get_field( 'linkedin', 'option' ) ?>" title="Find us on Linkedin"></a>
<?php endif; ?>
</div>
The shortcode works fine when I want to show the social icons in the footer of the theme but when I try to put them into the body (eg: the contact page) they are displaying absolute at the upper left hand corner of the page. See Screenshot: https://share.getcloudapp.com/8LuJkODx
I cannot figure out why this is happening - is there something I am doing wrong with get_template_part()?
Ahh..I see what the problem is. You need to return the value, not echo.
function social_icons_shortcode() {
$social_icons = get_template_part( 'includes/social_icons' );
return $social_icons;
}
add_shortcode('social-icons', 'social_icons_shortcode');
The other thing that may happen because how get_template_part() works, you may need to use an ob_buffer.
function social_icons_shortcode() {
ob_start();
get_template_part( 'includes/social_icons' );
return ob_get_clean();
}
add_shortcode('social-icons', 'social_icons_shortcode');
I have a WordPress blog and some of the articles are written by multiple authors, therefore I would like to display them on the post. Part of the goal has been achieved by installing the Co-Authors Plus plugin. This plugin only allows you to assign more than one author to the post but it won't automatically show both authors on the published post. For that I had to tweak the post-author.php file of my theme Mission News and I helped myself with this guide. I successfully edited the file (as seen in the code below), and now both names, Rachele and Collaboratore are displayed at the end of this post.
The original post-author.php file
<?php if ( get_theme_mod( 'author_box_posts' ) == 'no' ) return; ?>
<div class="post-author">
<?php if ( get_theme_mod( 'author_avatar_posts' ) != 'no' ) : ?>
<div class="avatar-container">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 78, '', get_the_author() ); ?>
</div>
<?php endif; ?>
<div>
<div class="author"><?php the_author(); ?></div>
<p><?php the_author_meta('description'); ?></p>
</div>
</div>
The edited post-author.php file
<?php if ( get_theme_mod( 'author_box_posts' ) == 'no' ) return; ?>
<div class="post-author">
<?php if ( get_theme_mod( 'author_avatar_posts' ) != 'no' ) :
if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
}?>
<div class="avatar-container">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 78, '', get_the_author() ); ?>
</div>
<?php endif; ?>
<div>
<p><?php the_author_meta('description'); ?></p>
</div>
</div>
I suppose the real problem here is my almost non-existent knowledge of php because I failed to correctly edit the content.php file which I believe is the file I need to edit in order to add both author names also in the text right under the title and next to the published date.
The content.php file contains the following lines:
<?php
$author = get_theme_mod( 'post_author_posts' );
$date = get_theme_mod( 'post_date_posts' );
?>
<div <?php post_class(); ?>>
<?php do_action( 'ct_mission_news_post_before' ); ?>
<article>
<?php ct_mission_news_featured_image(); ?>
<div class='post-header'>
<h1 class='post-title'><?php the_title(); ?></h1>
<?php ct_mission_news_post_byline( $author, $date ); ?>
</div>
<div class="post-content">
<?php ct_mission_news_output_last_updated_date(); ?>
<?php the_content(); ?>
<?php wp_link_pages( array(
'before' => '<p class="singular-pagination">' . esc_html__( 'Pages:', 'mission-news' ),
'after' => '</p>',
) ); ?>
<?php do_action( 'ct_mission_news_post_after' ); ?>
</div>
<div class="post-meta">
<?php get_template_part( 'content/post-categories' ); ?>
<?php get_template_part( 'content/post-tags' ); ?>
<?php get_sidebar( 'after-post' ); ?>
<?php get_template_part( 'content/post-author' ); ?>
</div>
<?php get_template_part( 'content/more-from-category' ); ?>
</article>
<?php comments_template(); ?>
</div>
I think I should be editing the <?php ct_mission_news_post_byline( $author, $date ); ?> line, but I don't know how. I tried a few things but none worked.
I would like to be able to display both names of the authors under the title of the post and next to the published date.
Thank you in advance to all those willing to help me.
Have a good day!
This:
(function_exists ('coauthors_posts_links')) {coauthors_posts_links ();}
The other:
{the_author_posts_link (); }
I don't have clickable header on my website. I want redirect to home page when I click on header. I don't know how the code should look to make it work.
This is my page-header.php code:
<div class="entry-header">
<div class="cv-outer">
<div class="cv-inner">
<div class="header-logo">
<?php
if ( has_custom_logo() ) :
$custom_logo_id = get_theme_mod( 'custom_logo' );
$custom_logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr( bloginfo('name') ); ?>" class="logo-img">
<img src="<?php echo esc_url( $custom_logo[0] ); ?>" alt="<?php esc_attr( bloginfo('name') ); ?>">
</a>
<?php else : ?>
<?php echo bloginfo( 'title' ); ?>
<?php endif; ?>
<?php if ( display_header_text() ) : ?>
<br>
<p class="site-description"><?php echo bloginfo( 'description' ); ?></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
I think I should add somethink here but I don't know PHP enough:
if ( has_custom_logo() ) :
$custom_logo_id = get_theme_mod( 'custom_logo' );
$custom_logo = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr( bloginfo('name') ); ?>" class="logo-img">
<img src="<?php echo esc_url( $custom_logo[0] ); ?>" alt="<?php esc_attr( bloginfo('name') ); ?>">
</a>
<?php else : ?>
<?php echo bloginfo( 'title' ); ?>
<?php endif; ?>
<?php if ( display_header_text() ) : ?>
<br>
<p class="site-description"><?php echo bloginfo( 'description' ); ?></p>
<?php endif; ?>
In additional I show you source of website in browser:
browser website source
All advice will be invaluable!
It looks like the title is empty.
In the else clause, if there is no custom logo, then a link will be displayed inside with text. The link is there, but it is not clickable because there is no text inside the link.
Can you check if bloginfo( 'title' ) is non-empty?
Another workaround would be to add a default picture that you know exists inside the link div, instead of text.
You just keep all header div in an Anchor element. Like below code
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
<div class="cv-inner">
<div class="header-logo">
</div>
</div>
</a>
I personally would put the PHP code in the definition for CV-Outer div.
<?PHP
if (has_custom_logo()) {
echo "<div class='cv-outer clickHeader'>" + PHP_EOL;
} else {
echo "<div class='cv-outer'>" + PHP_EOL;
}
?>
Then, just add an onclick handler to your javascript for the clickHeader class to redirect to the proper URL.
If you need to keep the custom logo from the PHP code, just leave it there, delete the bit that has the URL.
Basically, the problem is that the hyperlink isn't clickable because it has no size. Instead of messing with CSS to make it fit...I'd just remove it and use JS for the clickhandler...
Full HTML Code:
<div class="entry-header">
<?PHP
if (has_custom_logo()) {
echo "<div class='cv-outer clickHeader'>" + PHP_EOL;
} else {
echo "<div class='cv-outer'>" + PHP_EOL;
}
?>
<div class="cv-inner">
<div class="header-logo">
</div>
</div>
</div>
Sample Javascript:
<script>
window.onload = function() {
var headers = document.getElementsByTagName('clickHeader');
for(var i = 0; i < headers.length; i++) {
var header = headers[i];
header.onclick = function() {
document.location.href="/";
}
}
}
</script>
I've created a search page and using the loop return results based on users input. Problem is when I go to the search page it displays the search page title when the user hasn't entered anything. Is there a way I can remove the search page from the results? I've tried plugins but they don't work - am convinced there is something wrong with my loop but I don't see it.
My code is:
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
screenshot of bug thats happening:
Basically from my understand, you want it so that if the user goes to the search page, they don't see a title on the page that says 'Search Results for: ' with nothing after the colon. I have a proposed code change that will eliminate the title, and allow you to put a message for the user to search for something, to display results.
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php /* ADD THIS CODE */>
<?php $search_term = get_search_query(); ?>
<?php if (!empty($search_term)): /* if search term is not empty */ ?>
<?php /* END ADD THIS CODE */>
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
<?php /* ADD THIS CODE */>
<?php else: /* if search term is empty */ ?>
<p>Please enter some search text to display search results.</p>
<?php endif; ?>
<?php /* END ADD THIS CODE */>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
There are two code blocks to add, one up top, and one down low. Hope this helps!
EDIT (after clarification)
After we talked, it looks like the problem is related to the fact that you have a custom URL for the search page, something like '/search', which is actually a WordPress page labeled 'Search'. The problem is that when you load this search page, your loop already has one result in it, the current page. What you need to do is first check if your current loop is for the search, or if it is for the display of the search page. Do this like so:
<?php
/*
Template Name: Search Page
?>
<?php get_header(); ?>
<section id="post-<?php the_title(); ?>" class="search-section left <?php post_class(); ?>" role="main">
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<?php /* CHANGE THESE LINES FROM ABOVE, KEEP LOWER LINES */ ?>
<?php global $wp_query; ?>
<?php if (!empty($wp_query->query_vars['s'])): ?>
<?php /* END CHANGE THESE LINES FROM ABOVE, KEEP LOWER LINES */ ?>
<?php if ( have_posts() ) : ?>
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
<?php endif; ?>
<?php /* ADD THIS CODE */>
<?php else: /* if search term is empty */ ?>
<p>Please enter some search text to display search results.</p>
<?php endif; ?>
<?php /* END ADD THIS CODE */>
</div>
</section>
<aside class="search-sidebar right">
<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-4' ); ?>
<?php endif; ?>
</aside>
Keep the lower lines, and change those top lines to what I have. This is going to check that your loop is actually the loop that has the results of the search in it. If it is, then it draws the results, if not, then it displays the message below.
Try this:
<div class="search-input">
<form action="<?php echo home_url(); ?>" method="get" role="search" class="search-big">
<input type="text" name="s" id="s" class="search-big" placeholder="Type in your search and press enter..." />
</form>
</div>
<div class="search-result">
<h2><?php if( !empty( $_GET) ) { printf( __( 'Search results for: %s', 'xma' ), '<span>' . get_search_query() . '</span>' ); } ?></h2>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="search-single-result">
<a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p></a>
</div>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('Sorry, we couldn\'t find anything that matched your search.', 'xma' ); ?></h3>
Try this method which I found WordPress StackExchange
$exclude_pages = array('music', 'contact');
$exclude_post_types = array('music', 'any_here');
if ( have_posts() ) : while ( have_posts() ) : the_post();
if ( is_page() && ! empty($exclude_pages) && (
in_array($post->post_name, (array)$exclude_pages) ||
in_array($post->post_title, (array)$exclude_pages)
) ||
( is_single() && in_array(get_post_type(), (array)$exclude_post_types) ) ) continue;
Let me know if it works, or need improvement