Good day!
I have a strange issue with Wordpress 5.1.1. I have two pages with custom templates, a homepage and a blog page. On other pages I use standard template. And on standard pages I can see page title like About us - Sitename, Contacts - Sitename.
But on these custom pages it's empty! I can see only Sitename and title tag is empty. What it can be?
Also, I use custom WP_Query on a blog page.
UPD
This is my custom blog page:
<?php
/**
* Template Name: Статьи
*/
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 4, 'paged'=> $page ));
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
get_header();
the_title();
?>
<div id="blog_cards" class="ui grid">
<div class="sixteen wide column">
<div id="categories">
<?php
foreach( $categories as $category ) {
$category_link = sprintf(
'<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo $category_link;
}
?>
</div>
</div>
<div class="sixteen wide column">
<div class="ui two cards">
<?php
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="card">
<div class="image">
<?php the_post_thumbnail();?>
</div>
<div class="content">
<div class="header"><?php the_title();?></div>
<div class="meta">
<a><?php the_time('d.m.Y');?></a>
</div>
<div class="description">
<?php the_content();?>
</div>
</div>
<div class="extra content">
<?php
$post_cats = get_the_category();
foreach( $post_cats as $category ) {
$category_link = sprintf(
'<a class="category" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo $category_link;
}
?>
</div>
</div>
<?php endwhile;?>
</div>
</div>
<div class="sixteen wide column">
<?php if (function_exists('wp_corenavi')) wp_corenavi(array( 'wp_query' => $wp_query )); ?>
</div>
<?php
endif; ?>
</div>
<?php
do_action( 'storefront_sidebar' );
get_footer();
Also, I tried to call the_title() and it returned page title in a body of template. But title tag is empty.
And I use standard storefront theme for woocomerce.
Please move get_header() on the top of the page (before $page).
Related
I created a custom blog template in my WPLMS Wordpress theme, with wp-query. But I'm unable to show the pagination. I tried to build a shortcode its working fine but in the last im unable to show my pagination.
//blog section 2
add_shortcode('da-blog', 'da_blog_post');
function da_blog_post($attr, $content = null){
$attributes = extract( shortcode_atts(array(
'title' => 'blog post',
'subtitle' => 'latest news',
), $attr) );
ob_start(); ?>
<section class="exthree_blog">
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="all_exthree_blogs">
<div class="row">
<?php
$blogcontent = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'category__not_in' => array( 75 )
));
?>
<?php while($blogcontent->have_posts()) : $blogcontent->the_post(); ?>
<div class="col-md-4">
<div class="single_exthree_blog">
<div class="exthree_box">
<div class="exthree_box_img">
<!-- <img src="img/shutterstock_770159185.jpg" class="img-responsive"> -->
<a href="<?php echo get_permalink() ?>">
<?php if(has_post_thumbnail(get_the_ID())){ ?>
<?php echo get_the_post_thumbnail(get_the_ID(),'medium'); ?>
<?php }else{
$image = vibe_get_option('default_course_avatar');
?>
<img src="<?php echo vibe_sanitizer($image,'url'); ?>" />
<?php
}
$name = get_the_author_meta( 'display_name' );
?>
</a>
</div>
<div class="exthree_box_fortag">
</div>
<div class="boxxx">
<div class="exthree_box_title">
<h4><?php echo get_the_title(); ?></h4>
</div>
<div class="exthree_box_categor_list">
<?php echo get_the_category_list(); ?>
</div>
<div class="exthree_box_desc">
<p><?php echo get_the_excerpt(); ?></p>
</div>
<div class="exthree_box_button">
Continue<img src="http://localhost/gostudent/wp-content/uploads/2020/02/Layer-2.png">
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php echo "helooooooooooooooo"; ?>
<?php $big = 999999999; // need an unlikely integer
$links = paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $next_the_query->max_num_pages,
"type" => "list"
));
echo $links; ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php return ob_get_clean();
wp_reset_postdata();
}
I'm trying to display the title of a taxonomy term simply based on what the title of the taxonomy term is, NOT based on what posts are listed in the taxonomy.
Currently my taxonomy term and single post pages are displaying the titles of all taxonomies associated with each post.
For example...
I have a taxonomy called 'Residential', with a variety of terms associated with the taxonomy. Here's a link: http://desrosiers.robertrhu.com/residential/
There is a post called 'West Shore' that is associated with two taxonomy terms in the 'Residential' taxonomy, 'Renovations' and 'Contemporary'.
When I go to either the 'Contemporary' or 'Renovations' terms page OR to the 'West Shore' post, the heading lists BOTH taxonomy terms as the title. Here are some links: http://desrosiers.robertrhu.com/residential-category/contemporary/ and http://desrosiers.robertrhu.com/residential/west-shore/
So, if I click on 'Renovations', I want that page to only display the title 'Renovations'. If I click on 'Contemporary', I want that page to only display 'Contemporary'. And if I click on the single post in a particular taxonomy term, I want that single post to display the taxonomy term title that the post was navigated from.
Thanks in advance for your help!
Here is the code for the taxonomy term archive page:
<?php
/*
* Template Name: Residential Category Template
* Description: Template for Residential Project Types archive
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Taxonomy Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3 style="border-right: none; padding-left: 0;">
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h1>
<?php
$terms = get_the_terms( get_the_ID(), 'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
echo $term->name;
}
}
?>
</h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>
Here is the code for the single page:
<?php
/*
* Template Name: Residential Single Template
* Description: Template for Residential Project Types single
*/
get_header(); ?>
<div id="main-content">
<?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>
<!--Residential Single Header-->
<div id="residential-heading-single"
class="heading property-heading hide-for-small show-for-medium">
<h3>
<a href="<?php bloginfo('url'); ?>/residential/">
Residential
</a>
</h3>
<h3>
<?php
$terms = get_the_terms( get_the_ID(),
'residential_project_types' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
echo '<a href="' .esc_url( $term_link ) . '">' .
$term->name . '</a>';
}
}
?>
</h3>
<h1><?php the_field('project_title'); ?></h1>
</div>
<?php $terms = get_terms( array(
'taxonomy' => 'residential_project_types',
'orderby' => 'count',
'hide_empty' => true
) );
foreach( $terms as $term ) :
?>
<a class="property-thumb-link"
href="<?php echo get_term_link( $term ); ?>">
<div class="property-thumb column medium-6 small-12">
<img src="<?php the_field('category_image', $term); ?>"
alt="<?php the_field ('category_image_alt', $term); ?>" />
<div class="property-thumb-title">
<h2>
<?php echo $term->name; ?>
</h2>
</div>
</div>
</a>
<?php endforeach; ?>
</div>
<?php get_footer(); ?>
I am trying to query Wordpress custom posts and categories they are related to.
Query acts strangely, displays category name and all customs posts, not even related to that category (keeps repeating till all categorie names are displayed.)
Example image : Wordpress custom query display
My query code:
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="lookbook-header">
<div class="wrap">
<p class="text-left">lookbook</p>
</div>
</div>
<?php
$taxonomy = 'lookbook_categories';
$terms = get_terms($taxonomy);
$args=array(
'taxonomy' => 'lookbook_categories'
'post_type' => 'lookbook',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if ( $terms && !is_wp_error( $terms ) ) :
foreach ( $terms as $term ) { ?>
<div class="lookbook-category">
<p class="text-center">
<?php echo $term->name; ?>
</p>
</div>
<?php
if( $my_query->have_posts() ) {
echo '';
$count=0;
while ($my_query->have_posts()) : $my_query->the_post();
if($count == 3) {?>
<div class="row">
<?php }
?>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 no-padding">
<div class="lookbook-item">
<div class="hvrbox">
<?php
$image = get_field('lookbook_image');
if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" alt="news" class="img-responsive" />
<?php endif; ?>
<div class="hvrbox-layer_top">
<div class="hvrbox-text">
<div class="separator"></div>
<h3><?php the_title();?></h3>
<div class="separator"></div>
<p>
<?php the_field('excerpt');?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
$count++;
if($count == 3) echo '</div>';
endwhile;
}
}
endif;
wp_reset_query();
?>
</div>
</div>
I would like to display category name + posts related to category (not all posts over and over again)
You want to pass in an array to get_terms like:
$terms = get_terms( array(
'taxonomy' => 'lookbook_categories',
'hide_empty' => false,
) );
you can read more about it here: https://developer.wordpress.org/reference/functions/get_terms/
I created a Shortcode slider which gets ids of different pages and show display slider. Shordcode works fine but issue is that whenever i am copy past shortcode multiple times on same page/ template page it shows only first one.
This issue occurs only only when i past same type of shortcode but if i past any other shortcode on same page it works fine.
Here is my code
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is shortcode
[objectx-pages-list id="15,16,17"]
[objectx-pages-list ids="25,26,27"]
here you can see live example
http://objextheme.wpengine.com/
This one working fine
ROOFTOP PATIO & LOUNGE
but this is not working
This Week At Vertigo Sky Lounge
Please guide me where i am doing mistake. Thanks
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is the error i noticed. id="carousel-rooms" Id repeating on
same page. that is why only one time it runs perfect.
I am a wordpress n00b and am having issues with paging. I have the following "sample" loop code I am using:
<div id="content">
<?php /* Top post navigation */ ?>
<?php
$args = array(
'posts_per_page' => '25',
'cat' => '-33'
);
?>
<?php global $wp_query;
$wp_query = new WP_Query( $args );
$total_pages = $wp_query->max_num_pages;
if ( $total_pages > 1 ) { ?>
<?php } ?>
<?php /* The Loop — with comments! */ ?>
<?php while ( have_posts() ) : the_post() ?>
<?php /* Create a div with a unique ID thanks to the_ID() and semantic classes with post_class() */ ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php /* an h2 title */ ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php /* Microformatted, translatable post meta */ ?>
<div class="entry-meta">
<span class="meta-prep meta-prep-author"><?php _e('By ', 'hbd-theme'); ?></span>
<span class="author vcard"><a class="url fn n" href="<?php echo get_author_link( false, $authordata->ID, $authordata->user_nicename ); ?>" title="<?php printf( __( 'View all posts by %s', 'hbd-theme' ), $authordata->display_name ); ?>"><?php the_author(); ?></a></span>
<span class="meta-sep"> | </span>
<span class="meta-prep meta-prep-entry-date"><?php _e('Published ', 'hbd-theme'); ?></span>
<span class="entry-date"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time( get_option( 'date_format' ) ); ?></abbr></span>
<?php edit_post_link( __( 'Edit', 'hbd-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t" ) ?>
</div><!-- .entry-meta -->
<?php /* The entry content */ ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">»</span>', 'hbd-theme' ) ); ?>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'hbd-theme' ) . '&after=</div>') ?>
</div><!-- .entry-content -->
<?php /* Microformatted category and tag links along with a comments link */ ?>
<div class="entry-utility">
<span class="cat-links"><span class="entry-utility-prep entry-utility-prep-cat-links"><?php _e( 'Posted in ', 'hbd-theme' ); ?></span><?php echo get_the_category_list(', '); ?></span>
<span class="meta-sep"> | </span>
<?php the_tags( '<span class="tag-links"><span class="entry-utility-prep entry-utility-prep-tag-links">' . __('Tagged ', 'hbd-theme' ) . '</span>', ", ", "</span>\n\t\t\t\t\t\t<span class=\"meta-sep\">|</span>\n" ) ?>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'hbd-theme' ), __( '1 Comment', 'hbd-theme' ), __( '% Comments', 'hbd-theme' ) ) ?></span>
<?php edit_post_link( __( 'Edit', 'hbd-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t\n" ) ?>
</div><!-- #entry-utility -->
</div><!-- #post-<?php the_ID(); ?> -->
<?php /* Close up the post div and then end the loop with endwhile */ ?>
<?php endwhile; ?>
<?php /* Bottom post navigation */ ?>
<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<?php next_posts_link(__( '<span class="meta-nav">«</span> Older posts', 'hbd-theme' )) ?> <span style="color: #bbb;">•</span> <?php previous_posts_link(__( 'Newer posts <span class="meta-nav">»</span>', 'hbd-theme' )) ?>
</div><!-- #nav-below -->
<?php } ?>
</div><!-- #content -->
I have a feeling I am overwriting some query values, but I am finding contradicting information on various blogs. I have a feeling it has something to do with my $args array.
Am I supposed to concatenate that instead?
If so, where? $wp_query?
Thanks in advance for your help, and apologies for wordpress noob-ness.
I would add before your args
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; // setup pagination
and then in your args
$args = array(
'posts_per_page' => 25,
'cat' => '-33',
'paged' => $paged
);
following by using this to show the pagination
'<div class="classForOld">'.get_next_posts_link('Older', $wp_query->max_num_pages).'</div>'; //Older Link using max_num_pages
'<div class="classForNew">'.get_previous_posts_link('Newer', $wp_query->max_num_pages).'</div>'; //Newer Link using max_num_pages
Thats all you need.