Adding class to active taxonomy link in sidebar - javascript

i want to add a css class to taxonomy active link in my sidebar, i have this code..
function list_posts_by_taxonomy( $post_type, $taxonomy, $get_terms_args = array(), $wp_query_args = array() ){
$tax_terms = get_terms( $taxonomy, $get_terms_args );
if( $tax_terms ){
foreach( $tax_terms as $tax_term ){
$query_args = array(
'post_type' => $post_type,
"$taxonomy" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true
);
$query_args = wp_parse_args( $wp_query_args, $query_args );
$my_query = new WP_Query( $query_args );
if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $tax_term->slug; ?>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $tax_term->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $tax_term->slug; ?>">
<?php echo $tax_term->name; ?>
</a>
</h4>
</div>
<div id="collapse<?php echo $tax_term->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $tax_term->slug; ?>">
<div class="panel-body">
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php } wp_reset_query();
}
}
}
and it look like this
i want the the link in active page with different color such as red,
how can i do that.. thx guys

never mind, ive got my own solution here.., Thanks for the comment btw
<?php $IDOutsideLoop = $wp_query->post->ID; global $post; ?>
<?php
$taxonomyname = 'csis_project_category';
$taxonomyterms = get_terms($taxonomyname, 'hide_empty=0&hierarchical=0&order=DESC');
foreach ($taxonomyterms as $taxonomyterm) {
$args=array(
'post_type' => 'csis_project',
$taxonomyname => $taxonomyterm->name,
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $taxonomyterm->slug; ?>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $taxonomyterm->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $taxonomyterm->slug; ?>">
<?php echo $taxonomyterm->name; ?>
</a>
</h4>
</div>
<div id="collapse<?php echo $taxonomyterm->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $taxonomyterm->slug; ?>">
<div class="panel-body">
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li <?php if(is_singular( 'csis_project' ) && $IDOutsideLoop == $post->ID) { echo " class='current'"; } ?>><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php } wp_reset_postdata(); } ?>

Related

How to exclude custom post type Tag from the loop?

I'm trying to get all categories of custom post type "Services" with relative posts, but its showing tags also and I want to exclude the services taxonomy tags from the category list. Sorry I'm stuck on it to solve the issue. Please can someone help me to solve it?
<?php
$post_type = 'services';
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type, ) );
foreach( $taxonomies as $taxonomy ) :
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) : ?>
<?php
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1, //show all posts
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
)
)
);
$posts = new WP_Query($args);
if( $posts->have_posts() ): ?>
<section class="mb-5 pb-5">
<div class="container">
<div class="row text-center mb-5">
<h2 class="h4"><?php echo $term->name; ?></h2>
</div>
<div class="row justify-content-center">
<?php while( $posts->have_posts() ) : $posts->the_post(); ?>
<div class="col-6 col-md-3 mb-3 mb-lg-0">
<div class="card card-style-1 shadow-lg border-0 text-center">
<div class="mb-3">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="" class="img-fluid">
</div>
<div class="card-title">
<h3 class="h6 fw-normal"><?php echo the_title(); ?></h3>
</div>
</div>
</div>
<?php endwhile;
?>
</div>
</div>
</section>
<?php
endif; ?>
<?php endforeach;
endforeach; ?>
Try this:
<?php
$post_type = 'services';
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type, ) );
$exclude = array( 'post_tag' );
foreach( $taxonomies as $taxonomy ) :
if( in_array( $taxonomy->name, $exclude ) ) {
continue;
}
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) : ?>
<?php
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1, //show all posts
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
)
)
);
$posts = new WP_Query($args);
if( $posts->have_posts() ): ?>
<section class="mb-5 pb-5">
<div class="container">
<div class="row text-center mb-5">
<h2 class="h4"><?php echo $term->name; ?></h2>
</div>
<div class="row justify-content-center">
<?php while( $posts->have_posts() ) : $posts->the_post(); ?>
<div class="col-6 col-md-3 mb-3 mb-lg-0">
<div class="card card-style-1 shadow-lg border-0 text-center">
<div class="mb-3">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="" class="img-fluid">
</div>
<div class="card-title">
<h3 class="h6 fw-normal"><?php echo the_title(); ?></h3>
</div>
</div>
</div>
<?php endwhile;
?>
</div>
</div>
</section>
<?php
endif; ?>
<?php endforeach;
endforeach; ?>

load more articles button wordpress

I want to create a "load more articles" button that would generate 6 more articles. I have been looking online and found some tutorials, but they are for websites hosted in wordpress. my website only uses wordpress for news articles and posts them to my html page (I dont think its the right way to do it, but its what works for me at the moment)
Here is my site so far: http://futsoc.co/news/overview/recent-news/ (I corrected the link)
Here is what my code looks like so far. I want the new articles to be posted with the same format as the second loop:
I have a loop to show the 6 featured articles
<div class="row">
<?php $my_query = new WP_Query( 'category_name=featured&posts_per_page=6' );
while ( $my_query->have_posts() ) : $my_query->the_post();
$do_not_duplicate[] = $post->ID; ?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="col-sm-6 col-md-6 col-xl-4">
<article class="news-container">
<a href="<?php the_permalink();?>" class="news-link">
<div class="news-image">
<div class="news-img-bg" style="background-image: url('<?php echo $thumb['0'];?>')"></div>
</div>
<div class="news-info">
<p>
<i class="far fa-clock" style="padding-right:5px;"></i>
<?php echo get_the_date(); ?>
</p>
<h5>
<?php the_title(); ?>
</h5>
</div>
</a>
</article>
</div>
<?php endwhile; ?>
</div>
and I have a loop to show the 6 most recent articles (excluding the ones already featured)
<div class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
if ( in_array( $post->ID, $do_not_duplicate ) ) continue; ?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
<div class="col-sm-12 col-md-6">
<article class="news-container-small">
<a href="<?php the_permalink();?>" class="news-link-small">
<div class="news-image-small">
<div class="news-img-bg-small" style="background-image: url('<?php echo $thumb['0'];?>')"></div>
</div>
<div class="news-info-small">
<p>
<i class="far fa-clock" style="padding-right:5px;"></i>
<?php echo get_the_date(); ?>
</p>
<h5>
<?php the_title(); ?>
</h5>
</div>
</a>
</article>
</div>
<?php endwhile; endif; ?>
</div>

why pagination in my wordpress theme is not showing (wp-paginate plugin)

I use the rethink theme in wordpress, and use the wp-paginate plugin
in arcive.php, category.php and index.php pagination is fine
but why in page.php not running?
and I created my own template showing all the posts
posting.php
<?php
/*
Template Name: posting
*/
get_header();
?>
<div class="full-content">
<div class="grid_17 alpha">
<div class="content_bar">
<div class="feature_content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$count_posts = wp_count_posts();
$published_posts = $count_posts->publish;
$myposts = get_posts(array('posts_per_page'=>3)); ;
foreach($myposts as $post) :
setup_postdata($post);
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('product'); ?>>
<div class="post-info">
<h1 class="product_title">
<a href= "<?php the_permalink(); ?>" rel="bookmark" title="<?php echo sprintf(__("Permanent link to %s", 'rethink'), get_the_title(get_the_ID())); ?>">
<?php the_title(); ?>
</a>
</h1>
<div class="detail">
<ul class="post_meta">
<li class="admin"><?php printf(__("Posted by %s", 'rethink'), get_the_author_link()); ?></li>
<li class="date"><?php printf(__('Posted on %s', 'rethink'), get_the_time('F j, Y')); ?></li>
<li class="category"><?php the_category(','); ?></li>
<li class="commentt"><?php comments_popup_link(__('No Comments.', 'rethink'), __('1 Comment.', 'rethink'), __('% Comments.', 'rethink')); ?></li>
</ul>
</div>
</div>
<div class="post_thumbnail_wrapper">
<?php if (has_post_thumbnail()) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('post_thumbnail', array('class' => 'postimg')); ?>
</a>
<?php
} else {
echo rethink_main_image();
}
?>
</div>
<div class="product_content"><?php the_excerpt(); ?><div class="buttons"><a class="btn-2" href="<?php the_permalink() ?>"><span><?php _e('Read Review', 'rethink') ?></span></a></div>
</div>
</div>
<?php endforeach;
if(function_exists('wp_paginate')){
wp_paginate(); }
wp_reset_postdata(); ?>
<div class="clear"></div>
<?php endwhile;
else:
?>
<div class="product">
<p>
<?php _e('Sorry, no posts matched your criteria.', 'rethink'); ?>
</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="grid_7 omega">
<!--Start Sidebar-->
<?php get_sidebar(); ?>
<!--End Sidebar-->
</div>
</div>
<?php get_footer(); ?>
how i want to display the pagination of my coding ????
sorry if the line of code is not neat I still newbie
Update this Code:
if(function_exists('wp_paginate')){
wp_paginate();
}
to this code:
if(function_exists('wp_paginate')){
wp_paginate(array('page' => 'page'));
}

Remove Post View Count at the end of the Content

I have a 4.3 wordpress system that i install on it the "Orca Theme".
I notice i have duplicate indication of Post View Count:
I want to remove the First Indicator.
I try to look around amd search in the theme code and didnt find what display the First indicator.
postformat/standart.php:
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id, 'postlist', true);
$title_meta = get_post_meta($post->ID, 'title_style', true);
$title_meta = ($title_meta == ('banner' || 'title')) ? $title_meta : "standard";
$category = get_the_category();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> class="post standard">
<?php if($title_meta == "banner"){ ?>
<a class="basicfeature" href="<?php esc_url(the_permalink()); ?>" style="background-image:url('<?php echo esc_url($thumb_url[0]); ?>');"></a>
<h1><?php the_title(); ?></h1>
<?php }elseif($title_meta == "feature"){ ?>
<a href="<?php esc_url(the_permalink()); ?>" class="largeimage postfeature" style="background-image:url('<?php echo esc_url($thumb_url[0]); ?>');">
<div class="shadow"></div>
<h1><?php the_title(); ?></h1>
</a>
<?php }else{ ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
<div class="info">
<div class="left">
<i class="issticky fa fa-thumb-tack "></i><img src="http://0.gravatar.com/avatar/<?php echo esc_attr(md5(get_the_author_meta('user_email'))); ?>?s=32" alt="author" class="minigravatar"><?php the_author(); ?>
</div>
<div class="right">
<i class="fa fa-clock-o"></i><?php echo esc_html(orca_get_time()); ?>
<div class="category"><i class="fa fa-tags"></i>
<?php if($category){
echo '' . $category[0]->name.' ';
} ?>
</div>
</div>
</div>
<div class="postcontents">
<?php the_content('', FALSE, ''); ?>
</div>
<div class="footer">
<?php esc_html_e('Read More', 'orcawp'); ?>
<i class="fa fa-comments"></i><?php echo esc_html(get_comments_number($post->id)); ?>
<?php if(get_post_meta($post->ID, '_count-views_all', true) != ''){ ?>
<i class="fa fa-bullseye"></i><?php echo esc_html(get_post_meta($post->ID, '_count-views_all', true)); ?>
<?php } ?>
</div>
Solve it!
I just Deactivated the "BAW Post Views Count" plugin and now it removed!

Only show slider if one or more related items exist

I have a portfolio on a WordPress theme and on the single portfolio page it has a slider of related portfolio items. Well it's a cool feature but it shows the slider even if no related items match that particular portfolio item.
Here is my template where I display the slider:
<div class="related_portfolio">
<?php gbx_related_portfolio($post->ID); ?>
</div>
Here are my functions I am using to create my slider:
function get_related_portfolio($post_id) {
$item_cats = get_the_terms($post_id, 'portfolio_category');
if ($item_cats) {
foreach ($item_cats as $item_cat) $item_array[] = $item_cat->term_id;
}
$args = wp_parse_args($args, array(
'showposts' => 5,
'post__not_in' => array($post_id),
'ignore_sticky_posts' => 0,
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'id',
'terms' => $item_array
)
),
'orderby' => 'rand'
));
$query = new WP_Query($args);
return $query;
}
AND
function gbx_related_portfolio($post_id) {
?>
<div class="recentportfolio-wrapper">
<div class="image-carousel-header">
<div class="image-carousel-title"><span>Related Items</span></div>
<div class="image-carousel-nav">
<a class="prev"><i class="fa fa-chevron-left"></i></a><a class="next"><i class="fa fa-chevron-right"></i></a>
</div>
<div class="clear"></div>
</div>
<div class="iosslider recentportfolio-carousel <?php echo 'recentportfolio-carousel'.$randomid; ?>">
<ul><?php
$recentPortfolio = get_related_portfolio($post_id);
if ($recentPortfolio->have_posts()) {
while ( $recentPortfolio->have_posts() ) { $recentPortfolio->the_post(); global $post; ?>
<li class="portfolioslider_item">
<div class="portfolio-item">
<div class="image">
<a href="<?php the_permalink(); ?>">
<?php
if('' != get_the_post_thumbnail())
$full_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
else
$full_image = get_template_directory_uri().'/images/thumbnail_placeholder.png';
echo '<img class="size-full" src="' . gbx_process_image($full_image, 270, 240).'" alt="'.get_the_title(get_post_thumbnail_id($post->ID)).'"/>';
?>
</a>
<div class="image-extras">
<div class="image-extras-bg"></div>
<div class="image-extras-content">
<a class="icon" href="<?php the_permalink(); ?>"><span class="glyphicon glyphicon-paperclip"></span></a>
<a class="icon swipebox" href="<?php echo $full_image; ?>" title="<?php echo get_the_title($post->ID); ?>"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
<div class="portfolio-meta">
<div class="post-title"><?php the_title(); ?></div>
<div class="pull-left"><span class="glyphicon glyphicon-time"></span><?php echo get_the_date('F j, Y'); ?></div>
<div class="pull-right">
<span class="likeanimation"></span>
<a href="#" class="like <?php echo gbx_get_like_status($post->ID); ?>" title="<?php echo gbx_get_like_title($post->ID); ?>" data_action="likepost" data_postid="<?php echo $post->ID; ?>" data_nonce="<?php echo wp_create_nonce("gbx_like_nonce"); ?>">
<span class="glyphicon glyphicon-heart"></span>
<span class="likecount"><?php echo gbx_get_likecount($post->ID); ?></span>
</a>
<span class="glyphicon glyphicon-eye-open"></span><?php echo gbx_get_viewcount($post->ID); ?>
</div>
<div class="clear"></div>
</div>
</div>
</li>
<?php } } ?>
</ul>
</div>
</div>
<script>
(function($){
$(window).load(function() {
var $recentportfolio_carousel = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?>');
function custom_recent_portfolio_UpdateSliderHeight(args) {
var height = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?> .portfolioslider_item:eq(' + (args.currentSlideNumber-1) + ')').outerHeight(true);
$recentportfolio_carousel.css({ height: height });
}
$recentportfolio_carousel.iosSlider({
snapToChildren: true,
desktopClickDrag: true,
navPrevSelector: $recentportfolio_carousel.parent().find('a.prev'),
navNextSelector: $recentportfolio_carousel.parent().find('a.next'),
onSliderLoaded: custom_recent_portfolio_UpdateSliderHeight,
onSlideChange: custom_recent_portfolio_UpdateSliderHeight,
onSliderResize: custom_recent_portfolio_UpdateSliderHeight
});
});
})(jQuery);
</script>
<?php
}
Your code is quite mingled with a lot of syntax errors. I have put all your code in one function and rearrange it and fixed the errors. I'm not 100% sure about this part though, it is untested
function gbx_related_portfolio() {
wp_reset_postdata();
global $post;
$orig_post = $post;
if ( 'portfolio' == get_post_type() ) {
$tags = wp_get_post_terms($post->ID, 'portfolio_category');
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'terms' => $tag_ids,
'operator' => 'IN'
)
),
'post__not_in' => array( $post->ID ),
'posts_per_page' => 5,
'ignore_sticky_posts' => 0
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) { ?>
<div class="recentportfolio-wrapper">
<div class="image-carousel-header">
<div class="image-carousel-title"><span>Related Items</span></div>
<div class="image-carousel-nav">
<a class="prev"><i class="fa fa-chevron-left"></i></a><a class="next"><i class="fa fa-chevron-right"></i></a>
</div>
<div class="clear"></div>
</div>
<div class="iosslider recentportfolio-carousel <?php echo 'recentportfolio-carousel'.$randomid; ?>">
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li class="portfolioslider_item">
<div class="portfolio-item">
<div class="image">
<a href="<?php the_permalink(); ?>">
<?php
if('' != get_the_post_thumbnail())
$full_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
else
$full_image = get_template_directory_uri().'/images/thumbnail_placeholder.png';
?>
</a>
<div class="image-extras">
<div class="image-extras-bg"></div>
<div class="image-extras-content">
<a class="icon" href="<?php the_permalink(); ?>"><span class="glyphicon glyphicon-paperclip"></span></a>
<a class="icon swipebox" href="<?php echo $full_image; ?>" title="<?php echo get_the_title($post->ID); ?>"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
<div class="portfolio-meta">
<div class="post-title"><?php the_title(); ?></div>
<div class="pull-left"><span class="glyphicon glyphicon-time"></span><?php echo get_the_date('F j, Y'); ?></div>
<div class="pull-right">
<span class="likeanimation"></span>
<a href="#" class="like <?php echo gbx_get_like_status($post->ID); ?>" title="<?php echo gbx_get_like_title($post->ID); ?>" data_action="likepost" data_postid="<?php echo $post->ID; ?>" data_nonce="<?php echo wp_create_nonce("gbx_like_nonce"); ?>">
<span class="glyphicon glyphicon-heart"></span>
<span class="likecount"><?php echo gbx_get_likecount($post->ID); ?></span>
</a>
<span class="glyphicon glyphicon-eye-open"></span><?php echo gbx_get_viewcount($post->ID); ?>
</div>
<div class="clear"></div>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<script>
(function($){
$(window).load(function() {
var $recentportfolio_carousel = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?>');
function custom_recent_portfolio_UpdateSliderHeight(args) {
var height = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?> .portfolioslider_item:eq(' + (args.currentSlideNumber-1) + ')').outerHeight(true);
$recentportfolio_carousel.css({ height: height });
}
$recentportfolio_carousel.iosSlider({
snapToChildren: true,
desktopClickDrag: true,
navPrevSelector: $recentportfolio_carousel.parent().find('a.prev'),
navNextSelector: $recentportfolio_carousel.parent().find('a.next'),
onSliderLoaded: custom_recent_portfolio_UpdateSliderHeight,
onSlideChange: custom_recent_portfolio_UpdateSliderHeight,
onSliderResize: custom_recent_portfolio_UpdateSliderHeight
});
});
})(jQuery);
</script>
<?php
}
}
}
$post = $orig_post;
wp_reset_query();
}
Just call it as follows
<div class="related_portfolio">
<?php gbx_related_portfolio(); ?>
</div>

Categories