I need help in getting rid of a header in this code. It keeps adding a second header/banner to all pages except home.
I'm really not sure how to go about this. Below is the code, and the link to site is http://ultratest.com/ultratest/about-us/
Code on "banner.php"
<?php
/**
* Helper functions.
*
* #package Business_Kit
*/
if ( ( is_front_page()) || is_page_template( 'templates/home.php' ) ) {
return;
}
// Custom image.
$image_url = get_header_image();
if( !empty( $image_url ) ){
$banner_style = 'style="background: url('.esc_url( $image_url ).') top center no-repeat; background-size: cover;"';
} else{
$banner_style = '';
} ?>
<section id="featured-banner" class="overlay" <?php echo $banner_style; ?>>
<div class="container">
<div class="banner-title">
<?php
if(is_page() || is_single() ){ ?>
<h2><?php echo esc_html( get_the_title() ); ?></h2>
<?php
} elseif( is_search() ){ ?>
<h2><?php printf( esc_html__( 'Search Results for: %s', 'business-kit' ), '<span>' . get_search_query() . '</span>' ); ?></h2>
<?php
}elseif( is_404() ){ ?>
<h2><?php echo esc_html( 'Page Not Found: 404', 'business-kit'); ?></h2>
<?php
}elseif( is_home() ){ ?>
<h2><?php single_post_title(); ?></h2>
<?php
} else{
the_archive_title( '<h2>', '</h2>' );
}
?>
</div>
</div>
<?php get_template_part( 'template-parts/breadcrumbs' ); ?>
</section><!-- #main-banner -->
Related
I actually struggling with problem on this URL: Problematic URL
The problem can be described like this:
Page on that URL was set as main blog page in WordPress settings, but the page does not output list of posts, it just only outputs name of page "Herní články" and button read more (číst více) links to this page.. article id="post - id" showing classes "page type-page" and I really don't know how to resolve this problem..
The archive.php code is here:
<?php get_header(); ?>
<?php
$title_style = 'margin-bottom: 50px;';
$blog_content_style = 'margin-bottom: 30px;';
?>
<div id="primary" class="blog-content-area archive" style="<?php echo esc_attr($blog_content_style); ?>">
<?php
$title_color = (!empty($tdl_options['tdl_blog_title_color_scheme'])) ? $tdl_options['tdl_blog_title_color_scheme'] : 'mta-light';
$default_image_header = "";
if ( (isset($tdl_options['tdl_blog_default_header_bg']['url'])) && (trim($tdl_options['tdl_blog_default_header_bg']['url']) != "" ) ) {
$default_image_header = $tdl_options['tdl_blog_default_header_bg']['url'];
}
if ($default_image_header) {
$header_content_type = 'image';
$image_header = $default_image_header;
} else {
$header_content_type = '';
}
$title_align = $tdl_options['tdl_blog_title_align'];
?>
<?php
if ($header_content_type == 'image')
echo '<div class="site_header with_featured_img' . $no_parallax . '" style="' . $title_style . 'background-image:url(' . $image_header . ')">';
else
echo '<div class="site_header without_featured_img ' . $title_color . '" style="' . $title_style . '">';
?>
<div class="site_header_overlay"></div>
<div class="row">
<div class="large-12 <?php echo esc_attr( $title_align );?> large-centered columns">
<?php
if ((isset($tdl_options['tdl_shop_breadcrumb'])) && ($tdl_options['tdl_shop_breadcrumb'] == "1"))
{
// BREADCRUMBS
echo woodstock_breadcrumbs();
}
?>
<h1 class="page-title on-shop">
<?php
if ( is_category() ) :
single_cat_title();
elseif ( is_tag() ) :
single_tag_title();
elseif ( is_author() ) :
/* Queue the first post, that way we know
* what author we're dealing with (if that is the case).
*/
the_post();
printf( esc_html__( 'Author: %s', 'woodstock' ), '<span class="vcard">' . get_the_author() . '</span>' );
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
elseif ( is_day() ) :
printf( esc_html__( 'Day: %s', 'woodstock' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
printf( esc_html__( 'Month: %s', 'woodstock' ), '<span>' . get_the_date( 'F Y' ) . '</span>' );
elseif ( is_year() ) :
printf( esc_html__( 'Year: %s', 'woodstock' ), '<span>' . get_the_date( 'Y' ) . '</span>' );
elseif ( is_tax( 'post_format', 'post-format-aside' ) ) :
esc_html_e( 'Asides', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-image' ) ) :
esc_html_e( 'Images', 'woodstock');
elseif ( is_tax( 'post_format', 'post-format-video' ) ) :
esc_html_e( 'Videos', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-quote' ) ) :
esc_html_e( 'Quotes', 'woodstock' );
elseif ( is_tax( 'post_format', 'post-format-link' ) ) :
esc_html_e( 'Links', 'woodstock' );
else :
esc_html_e( 'Archives', 'woodstock' );
endif;
?>
</h1>
<?php
// Show an optional term description.
$term_description = term_description();
if ( ! empty( $term_description ) ) :
printf( '<div class="term-description"><p>%s</p></div>', $term_description );
endif;
?>
</div><!-- .large-12 -->
</div><!-- .row -->
</div><!-- .site_header -->
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<div class="row"><div class="large-8 columns with-sidebar">
<?php endif; ?>
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<!--masonry style-->
<?php if ( $blog_with_sidebar == "blog-masonry" ) : ?>
<div class="blog-isotop-master-wrapper">
<div class="row">
<div class="large-12 columns">
<div class="blog-isotop-container">
<div id="filters" class="button-group">
<button class="filter-item is-checked" data-filter="*">show all</button>
</div>
<div class="blog-isotope">
<div class="grid-sizer"></div>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="blog-post hidden <?php echo get_post_format(); ?>">
<div class="blog-post-inner">
<?php get_template_part( 'includes/content', get_post_format() ); ?>
<hr class="content_hr" />
</div><!--blog-post-inner-->
</div><!-- .blog-post-->
<?php endwhile; ?>
</div><!-- .blog-isotope -->
</div><!-- .blog-isotop-container-->
</div><!--.large-12-->
</div><!--.row-->
<?php woodstock_content_nav( 'nav-below' ); ?>
</div><!--blog-isotop-master-wrapper-->
<!--default style-->
<?php else : ?>
<?php if(is_author()) {
echo '<h1 class="author-name">Články od autora: '.get_the_author_meta('display_name', $author_id).'</h1>';
echo '<div class="author-description">'.get_the_author_meta('description', $author_id).'</div>';
} ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'includes/content', get_post_format() ); ?>
<hr class="content_hr" />
<?php endwhile; ?>
<?php woodstock_content_nav( 'nav-below' ); ?>
<?php endif; ?>
<!--no posts found-->
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
<?php if ( $blog_with_sidebar == "yes" ) : ?>
</div><!-- .columns -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<div class="large-4 columns">
<div class="row">
<div class="large-10 large-push-2 columns">
<?php get_sidebar(); ?>
</div>
</div>
</div><!-- .columns -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
</div><!-- .row -->
<?php endif; ?>
<?php if ( $blog_with_sidebar == "yes" ) : ?>
<?php if (is_active_sidebar( 'sidebar')) : ?>
<div id="button_offcanvas_sidebar_left"><i class="sidebar-icon"></i></div>
<?php endif; ?>
<?php endif; ?>
</div><!-- #primary -->
<?php get_footer(); ?>
Same code works well on this URL
I've already tried update WordPress but it still doesn't work, so I'm helpless..
Problem was resolved by switching theme, so, it was maybe some bug in WP.
I'm trying to use a repeater field and can't seem to get it to work. I think it's an issue with my if statement because if I remove the while loop and try echo out anything from <?php if( have_rows($aboutInfo['cards']): ?> I get nothing. I've tried without the ID, and a hardcoded ID as the 2nd param. Also, just to test I did <?php if( !have_rows($aboutInfo['cards']): ?> and was able to get something to echo out.
The print_r above the if statement displays the array.
<?
/*
Template Name: 01-Homepage
*/
get_header(); ?>
<? $aboutInfo = get_field( 'about' ) ?>
<?$postid = get_the_ID(); ?>
<div class="row">
<div class="columns small-12 medium-7">
<h2>
<?= $aboutInfo['title'] ?>
</h2>
<p class="lead"> <?= $aboutInfo['content'] ?></p>
<pre><?php print_r($aboutInfo['cards']) ?></pre>
<?php if( have_rows($aboutInfo['cards'], $postid) ): ?>
<?php while(have_rows($aboutInfo['cards'])) : the_row(); ?>
<?php $image = get_sub_field('image') ?>
<p><?= $image['url'] ?></p>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Here is what my ACF looks like
I think you are doing it wrong. There are so many bugs in your code. check
https://www.advancedcustomfields.com/resources/group/ and have_rows() the first param need to be selector. check below code.
<?php
/* Template Name: 01-Homepage */
get_header();
$aboutInfo = get_field( 'about' );
$postid = get_the_ID();
if( have_rows('about') ):
$title = get_sub_field('title');
$content = get_sub_field('content');
?>
<div class="row">
<div class="columns small-12 medium-7">
<?php while( have_rows( 'about' ) ): the_row(); ?>
<h2><?php echo $title; ?></h2>
<p class="lead"><?php echo $content; ?></p>
<?php if( have_rows( 'cards' ) ): while( have_rows( 'cards' ) ) : the_row(); ?>
<?php $image = get_sub_field( 'image' ); ?>
<img src="<?php echo $image['url']; ?>" />
<?php endwhile; endif;
endwhile; ?>
</div>
</div>
<?php endif;
get_footer(); ?>
The issues was that I created a group called "about" and the "cards" were nested in that group and to access that field I needed to use "about_cards".
<?
/*
Template Name: 01-Homepage
*/
get_header(); ?>
<?php while ( have_posts() ) : the_post();
// group field
$about = get_field( 'about' );
if ( !empty( $about ) ) { ?>
<div class="row">
<div class="columns small-12 medium-7">
<?php if ( !empty( $about['title'] ) ) { ?>
<h2><?php echo esc_html( $about['title'] ); ?></h2>
<?php }
if ( !empty( $about['content'] ) ) { ?>
<p class="lead"><?php echo wp_kses_post( $about['content'] ); ?></p>
<?php }
if( have_rows( 'about_cards' ) ) : // repeater
while ( have_rows( 'about_cards' ) ) : the_row();
$about_card_image = get_sub_field('image');
$about_card_title = get_sub_field('title');
$about_card_content = get_sub_field('content');
if ( !empty( $about_card_image ) ) {
echo wp_get_attachment_image( $about_card_image, 'medium' );
}
if ( !empty( $about_card_title ) ) {
echo '<h3>' . esc_html( $about_card_title ) . '</h3>';
}
if ( !empty( $about_card_content ) ) {
echo '<p>' . esc_html( $about_card_content ) . '</p>';
} ?>
<?php endwhile;
endif; ?>
</div>
</div>
<?php } // about field not empty ?>
<?php endwhile; // End of the loop. ?>
<?php get_footer(); ?>
I've been trying to split posts for a long time. I tried a variety of variations, but every time I post a single post or copy me all double.
I mean multiple posts.
If anyone has an idea how to fix it I will be very grateful to him.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'esteem_before_post_content' ); ?>
<?php
if( has_post_thumbnail() ) {
$image = '';
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'blog-large');
$title_attribute = the_title_attribute( 'echo=0' );
$image .= '<figure class="post-featured-image">';
$image .= '<a href="' . get_permalink() . '" title="'.the_title_attribute( 'echo=0' ).'">';
$image .= get_the_post_thumbnail( $post->ID, 'blog-large', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ) ) ).'</a>';
$image .= '<div class="mask">
<div class="image-icon-wrap">
<i class="icon-search"></i>
<i class="icon-link"></i>
</div>
</div>';
$image .= '</figure>';
echo $image;
}
?>
<div class="blog-content">
<header class="entry-header">
<h2 class="entry-title">
<?php the_title(); ?>
</h2><!-- .entry-title -->
</header>
<?php esteem_entry_meta(); ?>
<div class="entry-content clearfix">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</div>
<?php do_action( 'esteem_after_post_content' ); ?>
</article>
Post loop
<div id="primary">
<div id="content" class="clearfix">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php get_template_part( 'navigation', 'none' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
If anyone has an idea how to fix it I will be very grateful to him.
Since you are already calling post_class() function, you need to pass alternate class to that function itself and make sure to do this only on your custom page or selected blog page. The code will essentially be something like:
global $current_class;
$current_class = 'odd';
function alternating_post_class ( $classes ) {
global $current_class;
if( is_page(<PAGE_ID_HERE>) || is_home() ):
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
endif;
return $classes;
}
add_filter ('post_class', 'alternating_post_class');
This should resolve the problem by giving you odd/even class which you can use to style your two columns.
Cheers Mate!!!
I'm working on a Wordpress site and I have a header image on the homepage. It's only showing up on the homepage but I need it to show on every page. I found this code in the header.php file which I believe needs to be changed, but I'm not very familiar with php.
This is the code for the header image in the header.php file:
<?php $disable_page_title = get_post_meta( get_the_ID(), 'minimal_portfolio_page_title', true );
if( $disable_page_title !== 'on' ): ?>
<?php if( !is_front_page()): ?>
<section class="page-header jumbotron <?php if ( get_header_image() ) : ?>bg-image<?php endif; ?>" <?php if ( get_header_image() ) : ?> style="background-image:url('<?php echo esc_url( get_header_image() ); ?>');" <?php endif; ?>>
<?php if ( get_header_image() ) : ?><span class="bg-overlay"></span><?php endif; ?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="title-wrap">
<?php if( is_page() || is_single() ){ ?>
<h2 class="page-title"><?php echo esc_html( get_the_title() ); ?></h2>
<?php } elseif( is_search() ){ ?>
<?php /* translators: %s: search term */
$page_title = sprintf( esc_html__( 'Search Results for: %s', 'minimal-portfolio' ), get_search_query() );
?>
<h2 class="page-title"><?php echo esc_html( $page_title ); ?></h2>
<?php }elseif( is_404() ){ ?>
<h2 class="page-title"><?php echo esc_html( 'Page Not Found: 404', 'minimal-portfolio' ); ?></h2>
<?php }elseif( is_home() ){ ?>
<h2 class="page-title"><?php single_post_title(); ?></h2>
<?php } else{
the_archive_title( '<h2 class="page-title">', '</h2>' );
}
if( $minimal_portfolio_breadcrumb_status ):
minimal_portfolio_breadcrumbs();
endif;
?>
</div>
</div>
</div>
</div>
</section>
<?php endif;
endif; ?>
Thank you!
Edit: This is how it shows on all pages but the home page. But I would like it to show the full header instead of only a section of it with the page title.
Header
This is the home page, where it shows the full header and how I'd like it to show on every page instead of how it does in the image above.
Home Header
You are not familiar with PHP so you can use this plugin for the header image.
https://wordpress.org/plugins/unique-headers/
I think its work for you
Remove the below-attached code from header.php
<?php $disable_page_title = get_post_meta( get_the_ID(), 'minimal_portfolio_page_title', true );
if( $disable_page_title !== 'on' ): ?>
<?php if( !is_front_page()): ?>
<section class="page-header jumbotron <?php if ( get_header_image() ) : ?>bg-image<?php endif; ?>" <?php if ( get_header_image() ) : ?> style="background-image:url('<?php echo esc_url( get_header_image() ); ?>');" <?php endif; ?>>
<?php if ( get_header_image() ) : ?><span class="bg-overlay"></span><?php endif; ?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="title-wrap">
<?php if( is_page() || is_single() ){ ?>
<h2 class="page-title"><?php echo esc_html( get_the_title() ); ?></h2>
<?php } elseif( is_search() ){ ?>
<?php /* translators: %s: search term */
$page_title = sprintf( esc_html__( 'Search Results for: %s', 'minimal-portfolio' ), get_search_query() );
?>
<h2 class="page-title"><?php echo esc_html( $page_title ); ?></h2>
<?php }elseif( is_404() ){ ?>
<h2 class="page-title"><?php echo esc_html( 'Page Not Found: 404', 'minimal-portfolio' ); ?></h2>
<?php }elseif( is_home() ){ ?>
<h2 class="page-title"><?php single_post_title(); ?></h2>
<?php } else{
the_archive_title( '<h2 class="page-title">', '</h2>' );
}
if( $minimal_portfolio_breadcrumb_status ):
minimal_portfolio_breadcrumbs();
endif;
?>
</div>
</div>
</div>
</div>
</section>
<?php endif;
endif; ?>
And add this code in your page.php
<?php if( get_header_image() ) : ?>
<div class="header-banner">
<img src="<?php header_image(); ?>" width="<?php echo absint( get_custom_header()->width ); ?>" height="<?php echo absint( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</div>
On my WordPress site, I am using the following code to loop out my latest posts:
<?php
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
if ( 'post' === get_post_type() ) : ?>
<div class="entry-meta">
<?php blogtristan_posted_on(); ?> <span class="loopdivide"> | <span class="loop-time"><?php the_time( 'H:i' );?></span> (GMT)
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
$post = $post->post_content; /* or you can use get_the_title() */
$getlength = strlen($post);
$thelength = 200;
echo substr($post, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
How do I add a simple "Read more" button for each loop item?
Please try with below code
if (strlen($getlength) > 200) {
echo 'Read more';
}else{
echo $post;
}