I didn't find enough resource to know about owl carousel WordPress plugin. If you know please explain.
I'd get the image URL and simply loop through the post instances inside a While loop (or THE loop) - essentially, the basic loop for getting post assets.
I'm using the toolset plugin and calling the elements where needed using said loop.
<ul class="attributes">
<?php
$values = array(
// 'author_name' => 'author',
'post_type' => 'attribute',
'orderby' => 'id'
);
$query = new WP_Query( $values );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
$name = get_post_meta($post->ID, 'wpcf-value-name', true);
?>
<li>
<div class="values-content">
<div class="title">
<p><?php echo $name; ?></p>
</div>
<div class="text">
<p><?php echo get_post_meta($post->ID, 'wpcf-value-text', true); ?></p>
</div>
<div class="icon">
<?php $icons = get_post_meta($post->ID, 'wpcf-value-icon', true); ?>
<img src="<?php echo $icons; ?>" alt="<?php echo $name; ?>">
</div>
</div>
</li>
<?php endwhile; else: ?>
<p>Sorry, there are no posts to display</p>
<?php endif; ?>
</ul>
If you need any help with this, let me know. If you decide to stick with the plugin, that's fine but I'm not acquainted with it :) I'm calling the 'attributes' class name in the jQuery:
// carousel for about page values
jQuery(".attributes").owlCarousel({
autoWidth: true,
items: 1
});
Related
Evening all.
I need a little help. I have the following code which brings in a list of portfolios, and places them on a page in a grid format. At present the code brings in all the portfolio types (of which there are 3, divided into different categories). Is there a way I can edit the code so that I can bring in just one category type?
I have tried the following:
<?php query_posts( array( 'post_type' => 'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12));
but it displays a blank page.
If I remove:
'category_name' => 'news',
it returns a page will all the categories listed. I have checked the category name and all is correct but I'm clearly missing something.
I would be greatful if anyone could help.
Many thanks
The full code is:
<?php /* Template Name: Modular Gallery */ ?>
<?php get_header(); ?>
<div id="folio-wrap">
<ul id="portfolio-list" class="centerrow">
<?php query_posts( array( 'post_type'=>'myportfoliotype', 'category_name' => 'news','paged' => $paged, 'posts_per_page' => 12)); if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php $large_image=w p_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'fullsize', false, '' ); $large_image=$ large_image[0]; $another_image_1=g et_post_meta($post->ID, 'themnific_image_1_url', true); $video_input = get_post_meta($post->ID, 'themnific_video_url', true); ?>
<li id="post-<?php the_ID(); ?>" class="centerfourcol item_full">
<span class="imgwrap">
<?php the_post_thumbnail('folio',array('title' => "")); ?>
<a class="hoverstuff-zoom" rel="prettyPhoto[gallery]" href="<?php if($video_input) echo $video_input; else echo $large_image; ?>"><i class="icon-zoom-in"></i></a>
<a class="hoverstuff-link" href="<?php the_permalink(); ?>"><i class="icon-link"></i></a>
</span>
<div style="clear:both"></div>
<h3><?php echo short_title('...', 6); ?></h3>
<?php echo themnific_excerpt( get_the_excerpt(), '290'); ?>
</li>
<!-- #post-<?php the_ID(); ?> -->
<?php endwhile; endif; ?>
</ul>
<div class="clear"></div>
<div class="pagination">
<?php pagination( '«', '»'); ?>
</div>
<?php wp_reset_query(); ?>
</div>
</div>
<?php get_footer(); ?>
Your code should work if "news" is your category SLUG, not necessary the name.
But on some older versions of wordpress there is a bug with category_name in query_posts, try it with cat_name
I am in charge of managing this site F9 Properties which is built in WordPress. On the home page there is a featured properties section. I noticed that if you listed a property with two different "Status" such as "For Sale or For Lease, the property appeared twice in the carousel. Below is the code for listing the featured properties. I can see that it filters out the properties with the Status "Leased". Can anyone help me add a bit of code to list only one property per post regardless of how many different property status it has?
<?php
/* Featured Properties Query Arguments */
$featured_properties_args = array(
'post_type' => 'property',
'posts_per_page' => 100,
'meta_query' => array(
array(
'key' => 'REAL_HOMES_featured',
'value' => 1,
'compare' => '=',
'type' => 'NUMERIC'
)
)
);
$featured_properties_query = new WP_Query( $featured_properties_args );
if ( $featured_properties_query->have_posts() ) :
?>
<section class="featured-properties-carousel clearfix">
<?php
$featured_prop_title = get_option('theme_featured_prop_title');
$featured_prop_text = get_option('theme_featured_prop_text');
if(!empty($featured_prop_title)){
?>
<div class="narrative">
<h3><?php echo $featured_prop_title; ?></h3>
<?php
if(!empty($featured_prop_text)){
?><p><?php echo $featured_prop_text; ?></p><?php
}
?>
</div>
<?php
}
?>
<div class="carousel es-carousel-wrapper">
<div class="es-carousel">
<ul class="clearfix">
<?php
while ( $featured_properties_query->have_posts() ) :
$featured_properties_query->the_post();
?>
<?php
$status_terms = get_the_terms( $post->ID,"property-status" );
if(!empty( $status_terms )){
foreach( $status_terms as $status_term ){
if($status_term->name=="Leased"){}else{
?>
<li>
<figure>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php
the_post_thumbnail('property-thumb-image',array(
'alt' => get_the_title($post->ID),
'title' => get_the_title($post->ID)
));
?>
</a>
</figure>
<h4><?php the_title(); ?></h4>
<p><?php framework_excerpt(8); ?> <?php _e('Know More','framework'); ?> </p>
<span class="price"><?php property_price(); ?></span>
</li>
<?
}
}
}
?>
<?php
endwhile;
wp_reset_query();
?>
</ul>
</div>
</div>
I might be misunderstanding your setup, but I wonder why you're looping over the terms.
I think you should instead consider excluding the leased term within the WP_Query() part (hopefully you can share it).
Then your carousel would be simplified to:
<div class="carousel es-carousel-wrapper">
<div class="es-carousel">
<ul class="clearfix">
<?php while ( $featured_properties_query->have_posts() ) : $featured_properties_query->the_post(); ?>
<li><!-- YOUR POST ITEM HERE --></li>
<?php endwhile; ?>
</ul>
</div>
</div>
You can add the post ID to an array every time an iteration occurs, and check the array if the post has already been rendered:
$shown = array(); // new array
while ( $featured_properties_query->have_posts() ) :
$featured_properties_query->the_post();
$status_terms = get_the_terms( $post->ID, 'property-status' );
if( ! empty( $status_terms ) ){
foreach( $status_terms as $status_term ){
if( $status_term->name == "Leased" || in_array( $post->ID, $shown ){
continue; // post has term "Leased" or already rendered, skip
}
$shown[] = $post->ID; // add post ID to array
?>
<!-- HTML here -->
<?php
}
}
endwhile;
I'm trying to display 3 posts below my single post view (I have custom post types set up so want this query to work on all single post pages regardless of the post type).
However with the code below I don't get any related posts displayed. When I removed .'&exclude=' . $current I get 3 related posts display but with the current post being one of them. Hence why I added 'exclude' but I don't see why its not displaying any when I add this in.
Any help would be appreciate.
Thanks
<?php
$backup = $post;
$current = $post->ID; //current page ID
global $post;
$thisPost = get_post_type(); //current custom post
$myposts = get_posts('numberposts=3&order=DESC&orderby=ID&post_type=' . $thisPost .
'&exclude=' . $current);
$check = count($myposts);
if ($check > 1 ) { ?>
<h1 id="recent">Related</h1>
<div id="related" class="group">
<ul class="group">
<?php
foreach($myposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
<article>
<h1 class="entry-title"><?php the_title() ?></h1>
<div class="name-date"><?php the_time('F j, Y'); ?></div>
<div class="theExcerpt"><?php the_excerpt(); ?></div>
</article>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
$post = $backup;
wp_reset_query();
?>
</div><!-- #related -->
<?php } ?>
Instead of using get_posts(), you could use WP_Query
<?php
// You might need to use wp_reset_query();
// here if you have another query before this one
global $post;
$current_post_type = get_post_type( $post );
// The query arguments
$args = array(
'posts_per_page' => 3,
'order' => 'DESC',
'orderby' => 'ID',
'post_type' => $current_post_type,
'post__not_in' => array( $post->ID )
);
// Create the related query
$rel_query = new WP_Query( $args );
// Check if there is any related posts
if( $rel_query->have_posts() ) :
?>
<h1 id="recent">Related</h1>
<div id="related" class="group">
<ul class="group">
<?php
// The Loop
while ( $rel_query->have_posts() ) :
$rel_query->the_post();
?>
<li>
<a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
<article>
<h1 class="entry-title"><?php the_title() ?></h1>
<div class="name-date"><?php the_time('F j, Y'); ?></div>
<div class="theExcerpt"><?php the_excerpt(); ?></div>
</article>
</a>
</li>
<?php
endwhile;
?>
</ul><!-- .group -->
</div><!-- #related -->
<?php
endif;
// Reset the query
wp_reset_query();
?>
Try out the code above and modify it for your own need. Modified to suit your own markup.
I'm building a simple sidebar widget to display a loop of a custom post type "shows".
Each "show" has about 3 custom fields, which i'd like to output via the loop as well. This is the code i'm using:
This is the loop within my plugin code:
<?php
// WIDGET CODE GOES HERE
$args = array( 'post_type' => 'shows', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$month = get_post_meta($post->ID,'month-abbreviation',true);
$date = get_post_meta($post->ID,'date',true);
$citystate = get_post_meta($post->ID,'city-state',true); ?>
<article class="sidebar-show clearfix">
<a class="show-link" href="<?php the_permalink(); ?>">
<div class="date-box">
<span class="month"><?php echo $month; ?></span>
<span class="date"><?php echo $date; ?></span>
</div>
<div class="venue-box">
<?php echo "<h4>".get_the_title()."</h4>"; ?>
<?php echo "<p>".$citystate."</p>"; ?>
</div>
</a>
</article>
<?php endwhile;
wp_reset_query();
wp_reset_postdata();
?>
<?php
echo $after_widget;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("ShowsSidebarWidget");') );?>
This code pulls in the post titles, but doesn't display the custom fields month-abbreviation, date, and city-state.
What's missing here?
EDIT: Removed double quotes after avexdesign's reply.
are you sure $post->ID is available in this context?
maybe you should try: get_the_ID() instead.
Ok, I see a few things you can try.
month-abbreviation - should be single quotes. Like 'month-abbreviation'
Try taking out: $month= $date= and $citystate =
Might need echo
So Try:
echo get_post_meta($post->ID,'month-abbreviation', true);
echo get_post_meta($post->ID,'date', true);
echo get_post_meta($post->ID,'city-state', true);
Try something like:
<?php $loop = new WP_Query( array( 'post_type' => 'shows', 'posts_per_page' => 10 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<span class="month"><?php echo get_post_meta($post->ID, 'month-abbreviation', true); ?></span>
<span class="date"><?php echo get_post_meta($post->ID, 'date', true); ?></span>
and so on... for your other custom IDs
I have a blog, and I have added one custom post type 'Movies'. and I have link it to my single-movies.php. and added this code:
<div id="container">
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1, 'name' => $_GET['movie'] );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1>
<a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php include(TEMPLATEPATH . '/sidebar_single.php'); ?>
<?php get_footer(); ?>
But Problem is, I'm clicking on any movie, its showing me only same movie, which i have added last on custom field Movies (i.e Avatar Movie, if I click on stargate movie, Its showing me 'Avatar' Movie link. and same others)
Please help me and change this code, if I did anything wrong here.
when you are in single-movies.php
it means you are already on the right path like /movies/avatar
so doing a simple loop
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); //.... ?>
<?php endwhile; ?>
gives you all details of the avatar movie, you don't need to query, because the query is already made by the time you arrive to a SINGLE Movie page!
/movies/avatar means:
post type = movies
post name = avatar
also if you have pretty links, $_GET['movie'] it normally contains nothing.
it is prefered to use the $wp->query_vars['post_name'] to get the movie name
try just putting the loop and see what you get, if not dump the $_GET and $wp to see where you have the movie name.
you have a problem with the loop.
I would say to use a foreach...look at this example, maybe it will help you. it is exactly the same as you want to achieve.
<?php
$cat_id = $category->cat_ID; // YOU CAN CHANGE THIS OR REMOVE
global $post;
$args = array( 'category' => $cat_id, 'numberposts' => -1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : start_wp();
?>
<li class="subcat-post-title">
<span class="trigger">
<a class="ficha" href="<?php the_permalink() ?>">
<?php echo the_title(); ?>
</a>
<?php endforeach; ?>