I'm trying to capitalise the Wordpress portfolio category string of "Corporate identity".
I have tried using this post: Capitalise every word of a string in PHP?, but have had no luck.
URL: http://utopia.gerandeklerk.com/
On the home page, hover over the first portfolio item (Steam Africa 2014), you will notice on the hover-state it lists the portfolio categories "Collateral" and "Corporate identity". The client wants wants it to display "Corporate Identity", as it does in the category filter menu above it.
I added the following string - can someone tell me where I went wrong?
$portfolio_category[] = ucwords(strtolower($term->slug)); // Capitalise Portfolio Category String
Below is the code from portfolio.php
<div class="filter-container">
<ul data-drop-content class="filter-list">
<li>All</li>
<?php
$terms = get_terms("portfolio_category");
foreach ( $terms as $term ) {
echo "<li><a href='#' data-filter='" . "." . strtolower($term->slug) . "'>" . $term->name . "</a></li>";
};
?>
</ul>
<span>| More filters</span> <img src="<?php echo get_template_directory_uri(); ?>/images/down-arrow.png">
<?php
$desired_width = 440;
$desired_height = 440;
if(is_tax()) { // is category page
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args = array( 'post_type' => 'portfolio', 'portfolio_category' => $term -> slug, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order'=>'ASC' );
}
else { // is main portfolio page
$args = array( 'post_type' => 'portfolio', 'posts_per_page' => -1, 'orderby' => 'menu_order','order'=>'ASC' );
}
$loop = new WP_Query( $args );
if($loop->have_posts()) {
?>
<div class="portfolio-gallery group isotope">
<?php
//output the latest projects from the 'my_portfolio' custom post type
while ($loop->have_posts()) : $loop->the_post();
?>
<?php
$terms = get_the_terms( $post->ID, 'portfolio_category' );
if ( $terms && ! is_wp_error( $terms ) ) {
$portfolio_category = array();
foreach ( $terms as $term ) {
$portfolio_category[] = ucwords(strtolower($term->slug)); // Capitalise Portfolio Category String
}
$the_tax = join( " ", $portfolio_category );
} else {
$the_tax = "";
};
?>
<div class="portfolio-item <?php echo $the_tax; ?> portfolio-item-<?php the_ID(); ?>">
<a class="project-link" href="<?php the_permalink(); ?>">
<div class="thumb-container">
<div class="portfolio-thumb">
<?php if( get_field('gray_scale_image') ): ?>
<img src="<?php the_field('gray_scale_image'); ?>" class="grey-scale-image" />
<?php endif; ?>
<?php if( get_field('gray_scale_image') ): ?>
<img src="<?php the_field('colour_image'); ?>" class="colour-image" />
<?php endif; ?>
</div>
</div><!-- /.thumb-container -->
</a><!-- /.project-link -->
<h3 class="portfolio-category"><?php echo str_replace('-',' ',ucwords(join(", ", explode(" ", $the_tax))) ); ?></h3>
<h3 class="portfolio-title"><?php the_title(); ?></h3>
</div><!-- /.portfolio-item -->
<?php endwhile; ?>
</div><!-- .portfolio-gallery -->
<?php } // end if ?>
It goes wrong on this line
<h3 class="portfolio-category"><?php echo str_replace('-',' ',ucwords(join(", ", explode(" ", $the_tax))) ); ?></h3>
On this line you can try the following function as you mentioned earlier
$bar = ucwords(strtolower($bar)); // Hello World!
I Didn't tested the code
Related
I need to insert a pagination to the post instead of the load more button and I don't know how how to do it. I require pagination of Next & Previous or numbers.
Here's our dev work, but I don't know where to start or where I should put this example.
<?php
/*
* Template Name: Blog
* description: >-
Page template without sidebar
*/
get_header(); ?>
<body class=" pageHeader--gray">
<div class="wrapper">
<div class="content">
<div class="pageHeader">
<div class="container animate">
<h1 class="pageHeader__title"><?php the_field('title'); ?>
</h1>
</div>
<div class="pageHeader__background">
<svg xmlns="http://www.w3.org/2000/svg" width="1920" viewBox="0 0 1920 126">
<path fill="#FFF" fill-rule="evenodd" d="M9.09494702e-13,7.95807864e-13 L1920,7.95807864e-13 L1920,22.1174168 C1622.41146,91.3724723 1302.41146,126 960,126 C617.588542,126 297.588542,91.3724723 9.09494702e-13,22.1174168 L9.09494702e-13,7.95807864e-13 Z" transform="rotate(180 960 63)"></path>
</svg>
</div>
<div class="pageHeader__decor animate animate--wrapper">
<div class="pageHeader__decor-1 animate__child">
</div>
<div class="pageHeader__decor-2 animate__child">
</div>
</div>
</div>
<div class="blog">
<div class="container">
<div class="blog__tags animate">
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
$active = "";
if ( null == #$_GET['category_id'] ) {
$active = "active";
}
echo '<a class="blog__tag '.$active.'" href="'. site_url() .'/blog">All Categories</a>';
foreach( $categories as $category ) {
$active = "";
if ( $category->name == #$_GET['category_id']) {
$active = "active";
}
echo '<a class="blog__tag '.$active.'" href="'. site_url() .'/blog?category_id='.$category->name.'">'.$category->name.'</a>';
}
?>
</div>
<div class="blog__wrapper">
<?php
$args = array(
'posts_per_page' => 1,
'post__in' => get_option( 'sticky_posts' ),
'ignore_sticky_posts' => 1,
'category_name' => #$_GET['category_id']
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
?>
<a class="newsCard newsCard--big animate" href="<?php the_permalink(); ?>">
<?php if (has_post_thumbnail( get_the_ID() ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' ); ?>
<div class="newsCard__image"><img src="<?php echo $image[0]; ?>" alt=""/></div>
<?php endif; ?>
<div class="newsCard__content">
<div class="newsCard__tag">
<?php
$categories="";
foreach((get_the_category()) as $category){
$categories = $category->name.",";
}
echo substr($categories, 0, -1);
?>
</div>
<div class="newsCard__title"><?php the_title(); ?>
</div>
<div class="newsCard__description"><?php the_excerpt(); ?>
</div>
<div class="newsCard__link">Learn more
<div class="newsCard__link-icon">
</div>
</div>
</div>
</a>
<?php
endwhile;
wp_reset_postdata();
?>
<?php
$load = 0;
$total_post =wp_count_posts()->publish;
if (null !== #$_GET['load']){
$load = $_GET['load'];
}
$i = 6 + $load;
?>
<?php
// the query
$wpb_all_query = new WP_Query(array(
'post_type'=>'post',
'post_status'=>'publish',
'posts_per_page'=>$i,
'ignore_sticky_posts' => 1,
'category_name' => #$_GET['category_id']
));
$count = $wpb_all_query->found_posts;
?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<a class="newsCard newsCard animate" href="<?php the_permalink(); ?>">
<?php if (has_post_thumbnail( get_the_ID() ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' ); ?>
<div class="newsCard__image"><img src="<?php echo $image[0]; ?>" alt=""/></div>
<?php endif; ?>
<div class="newsCard__content">
<div class="newsCard__tag">
<?php
$categories="";
foreach((get_the_category()) as $category){
$categories = $category->name.",";
}
echo substr($categories, 0, -1);
?>
</div>
<div class="newsCard__title"><?php the_title(); ?>
</div>
<div class="newsCard__description"><?php the_excerpt(); ?>
</div>
<div class="newsCard__link">Learn more
<div class="newsCard__link-icon">
</div>
</div>
</div>
</a>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
<?php if( null == #$_GET['load'] && $count > 6 ) : ?>
<div class="blog__button animate">
<?php
if ( null == #$_GET['category_id'] ) {
?>
<a class="btn" href="<?php echo site_url(); ?>/blog?load=<?php echo $load + $total_post; ?>"><?php the_field('load_more_button_label'); ?></a>
<?php
} else {
?>
<a class="btn" href="<?php echo site_url(); ?>/blog?category_id=<?php echo $_GET['category_id']; ?>&load=<?php echo $load + $total_post; ?>"><?php the_field('load_more_button_label'); ?></a>
<?php
}
?>
</div>
<?php endif; ?>
</div>
</div>
<div class="achievments">
<div class="container">
<div class="blockTitle blockTitle--center blockTitle--small">
<h2><?php the_field('achievement_title'); ?></h2>
</div>
<div class="rewardsCards2 animate animate--wrapper">
<?php
// the query
$wpb_all_query = new WP_Query(array(
'post_type'=>'achievement_cpt',
'post_status'=>'publish',
'posts_per_page'=>-1,
// 'ignore_sticky_posts' => 1,
// 'meta_key' => 'departament',
// 'meta_value' => 'Information Technology and Security'
));
?>
<?php if ( $wpb_all_query->have_posts() ) : ?>
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
<div class="rewardsCards2__item animate__child"><img src="<?php echo get_field('image', get_the_ID()); ?>" alt=""/>
<div class="rewardsCards2__tooltip">
<div class="rewardsCards2__tooltip-logo"><img src="<?php echo get_field('image', get_the_ID()); ?>" alt=""/>
</div>
<div class="rewardsCards2__tooltip-content">
<div class="rewardsCards2__tooltip-title"><?php echo get_field('title', get_the_ID());?>
</div>
<div class="rewardsCards2__tooltip-description"><?php echo get_field('content', get_the_ID());?>
</div><a class="rewardsCards2__tooltip-link" href="<?php echo get_field('url',get_the_ID());?>">Read More</a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
</div>
</div>
<?php get_footer('phone'); ?>
</div>
</body>
<?php get_footer(); ?>
So I'm not going to repeat what's already said in the article, but I hope these help you:
Remove the $load (or $_GET['load']) and $i part:
// Find and remove this:
$load = 0;
$total_post =wp_count_posts()->publish;
if (null !== #$_GET['load']){
$load = $_GET['load'];
}
$i = 2 + $load;
Add paged in the first // the query. We also set a static posts_per_page, although you may make it dynamic later.
// Find and replace this:
// the query
$wpb_all_query = new WP_Query(array(
'post_type'=>'post',
'post_status'=>'publish',
'posts_per_page'=>$i,
'ignore_sticky_posts' => 1,
'category_name' => #$_GET['category_id'],
));
$count = $wpb_all_query->found_posts;
// With this one:
// the query
$wpb_all_query = new WP_Query(array(
'post_type'=>'post',
'post_status'=>'publish',
// Set a static posts_per_page value.
'posts_per_page'=> 6,
'ignore_sticky_posts' => 1,
'category_name' => #$_GET['category_id'],
// Add the "paged" arg.
'paged' => max( get_query_var( 'paged' ), 1 ),
));
// The $count is not needed (anymore).
After that, find and replace this:
<?php if( null == #$_GET['load'] && $count > 6 ) : ?>
<div class="blog__button animate">
<?php
if ( null == #$_GET['category_id'] ) {
?>
<a class="btn" href="<?php echo site_url(); ?>/blog?load=<?php echo $load + $total_post; ?>"><?php the_field('load_more_button_label'); ?></a>
<?php
} else {
?>
<a class="btn" href="<?php echo site_url(); ?>/blog?category_id=<?php echo $_GET['category_id']; ?>&load=<?php echo $load + $total_post; ?>"><?php the_field('load_more_button_label'); ?></a>
<?php
}
?>
</div>
<?php endif; ?>
With one of the following, whichever you prefer (either simple or numerical pagination):
1) Simple previous-and-next Pagination
Here, we are using previous_posts_link() and next_posts_link().
<?php
if ( $wpb_all_query->max_num_pages > 1 ) :
$paged = max( get_query_var( 'paged' ), 1 );
?>
<div class="simple-pagination"><?php
previous_posts_link( '← Older Posts' );
if ( $paged > 1 && $paged < $wpb_all_query->max_num_pages ) {
echo ' <span class="sep">•</span> ';
}
next_posts_link( 'Newer Posts →', $wpb_all_query->max_num_pages );
?></div>
<?php endif; ?>
2) Numerical Pagination
Here, we are using paginate_links() — please check the function reference for more details on the parameters.
<?php
$links = paginate_links( array(
'total' => $wpb_all_query->max_num_pages,
'prev_text' => '← Older Posts',
'next_text' => 'Newer Posts →',
) );
if ( $links ) {
echo "<div class='numeric-pagination'>$links</div>";
}
?>
Two important things to note:
In your new WP_Query() call, the args need to have the paged arg so that WordPress knows the current page number and then retrieves only the posts for that specific page.
With next_posts_link() and paginate_links(), you need to pass the $wpb_all_query->max_num_pages which is the total number of pages for your custom WordPress query (WP_Query).
That's all, and once again, I hope this answer helps and note that I used only basic HTML in my examples above, so just modify it to your liking.
Paste this code in functions.php
<?php
//Custom pagination
function the_pagination() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<ul class="pagination " itemscope itemtype="http://schema.org/SiteNavigationElement/Pagination">' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( ' <li class="page-item">%s</li>
' . "\n", get_previous_posts_link('
<span aria-hidden="true" class="page-link ripple">«</span>
<span class="sr-only">Previous</span>
') );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="page-item active"' : '';
printf( '<li%s class="page-item">%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="page-item active"' : '';
printf( '<li%s class="page-item">%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="page-item active"' : '';
printf( '<li%s class="page-item">%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li class="page-item ">%s</li>
' . "\n", get_next_posts_link('<span aria-hidden="true" class="page-link ripple">»</span>
<span class="sr-only">Next</span>') );
echo '</ul>' . "\n";
}
?>
And use <?php the_pagination(); ?> where you want the pagination
Maybe I'm going about this incorrectly but I'm having an issue with getting info outside of the while loop:
<?php
$title = get_field('car_list_title');
$field = get_field('tax_field_selector');
$query = new WP_Query( array(
'post_type' => 'cars',
'taxonomy' =>'make',
'term' => $field->name,
'posts_per_page' => -1,
'orderby' =>'title',
'order' =>'ASC'
) );
$taxonomy = get_terms( array(
'taxonomy' => 'location',
'hide_empty' => true
) );
if ( $field || $query->have_posts() ) :
?>
<div class="c-cars">
<h2 class="c-cars_title u-t--underline--lightblue">
<?= $title; ?>
</h2>
<?php foreach( $taxonomy as $tax ) :
$tax_name = $tax->name;
?>
<div class="c-cars_row">
<h4 class="c-cars_location-title">
<?= $tax_name; ?>
</h4>
<div class="c-cars_cars">
<?php while ( $query->have_posts() ) : $query->the_post();
$title = get_the_title();
$link = get_permalink();
$image = get_field('car-picture');
$image_alt = get_field('car_alt');
$image_title = get_field('car_title');
$post_id = get_the_ID();
$terms = get_the_terms( $post_id, 'location', array( 'order' => 'DESC', 'hide_empty' => true));
$location = $terms[0]->name;
?>
<?php if( $location === $tax_name ) : ?>
<div class="c-cars_car">
<a href="<?= $link; ?>">
<img class="c-cars_car-image" src="<?= $image; ?>" alt="<?= $image_alt; ?>" title="<?= $image_title; ?>">
</a>
<h4 class="text-center">
<a href="<?= $link; ?>">
<?= $title; ?>
</a>
</h4>
</div>
<?php endif; ?>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
So what happens here is I get a list of the locations and all the cars in those locations:
Location 1:
Car
Car
Car
Location 2:
Car
Car
Car
Location 3:
Location 4:
Car
Car
Car
The problem here is, as an example, Location 3 shows up even though there's no "posts" in that term.
The while loop is only cars of a specific model, sorted into what location they are at.
I'm not really sure how to filter out the empty locations.
I do:
<?php if( $location === $tax_name ) : ?>
Inside of the loop and that filters them out of the locations but still leaves the location title because it's outside of the while loop. If I were able to do this earlier up in the code it may work but I can't get the list of active terms outside of the while loop.
I'm kind of lost right now. Any ideas or suggestions? Thanks!
you can check using condition if has a term so show title either it will be blank try it below condition and mentioned in a comment if it's work or not.
has_terms
https://developer.wordpress.org/reference/functions/has_term/
function check if the post has terms.
if( has_term( $location, $tax_name ) ) {
// do something
}
Okay, I have updated your answer please try it below code. I have just get post count of terms and applied condition if terms has post count so show terms title name or if there is no post count of terms so the title will show blank.
<?php
$title = get_field('car_list_title');
$field = get_field('tax_field_selector');
$query = new WP_Query( array(
'post_type' => 'cars',
'taxonomy' =>'make',
'term' => $field->name,
'posts_per_page' => -1,
'orderby' =>'title',
'order' =>'ASC'
) );
$taxonomy = get_terms( array(
'taxonomy' => 'location',
'hide_empty' => true
) );
if ( $field || $query->have_posts() ) :
?>
<div class="c-cars">
<h2 class="c-cars_title u-t--underline--lightblue">
<?= $title; ?>
</h2>
<?php foreach( $taxonomy as $tax ) :
$tax_name = $tax->name;
$tax_post_count = $tax->count;
?>
<div class="c-cars_row">
if ( $tax_post_count > 0 ) : ?>
<h4 class="c-cars_location-title">
<?= $tax_name; ?>
</h4> <?php
else : ?>
<h4 class="c-cars_location-title">
<?= $tax_name = ''; ?>
</h4> <?php
endif; ?>
<div class="c-cars_cars">
<?php while ( $query->have_posts() ) : $query->the_post();
$title = get_the_title();
$link = get_permalink();
$image = get_field('car-picture');
$image_alt = get_field('car_alt');
$image_title = get_field('car_title');
$post_id = get_the_ID();
$terms = get_the_terms( $post_id, 'location', array( 'order' => 'DESC', 'hide_empty' => true));
$location = $terms[0]->name;
?>
<?php if( $location === $tax_name ) : ?>
<div class="c-cars_car">
<a href="<?= $link; ?>">
<img class="c-cars_car-image" src="<?= $image; ?>" alt="<?= $image_alt; ?>" title="<?= $image_title; ?>">
</a>
<h4 class="text-center">
<a href="<?= $link; ?>">
<?= $title; ?>
</a>
</h4>
</div>
<?php endif; ?>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
I'm trying to get an unformatted list (preferably a list of slugs) of the categories for a single post in a custom post type loop. This list will eventually serve as a class for a div ($CATEGORYSLUGSWILLEVENTUALLYGOHERE).
I've found a few different methods of getting a list of ALL of the categories for a custom post type, but not the ones specific to a single one. Here's what I have so far:
<?php $projects_loop = new WP_Query( array( 'post_type' => 'projects', 'orderby' => 'menu_order' ) ); ?>
<?php while ( $projects_loop->have_posts() ) : $projects_loop->the_post(); ?>
<div class="box <?php $CATEGORYSLUGSWILLEVENTUALLYGOHERE; ?>">
<div class="port-item-home">
<?php the_post_thumbnail( 'portfolio-home' ); ?>
<p><?php the_title(); ?></p>
</div>
</div>
<?php endwhile; ?>
And here's what I've tried so far to get the category list:
<?php
$args = array(
'orderby' => 'name',
'parent' => 0,
'taxonomy' => 'project-type'
);
$categories = get_categories( $args );
echo '<p> '.print_r(array_values($categories)).'something</p>'
?>
I have it returning the array - but the array is showing that it'll display all categories instead of the ones pertaining to that specific post.
I also tried:
<?php
//list terms in a given taxonomy (useful as a widget for twentyten)
$taxonomy = 'project-type';
$tax_terms = get_terms($taxonomy);
?>
<?php
foreach ($tax_terms as $tax_term) {
echo $tax_term->name;
}
?>
And that also displays all categories instead of the ones pertaining to the post.
Any suggestions??
Got it! Found this article that helped me out:
https://wordpress.org/support/topic/how-to-get-the-category-name-for-a-custom-post-type
<!-- The Query -->
<?php
$args = array(
'post_type' => 'my_post_type',
'posts_per_page' => -1,
'orderby' => 'menu_order' );
$custom_query = new WP_Query( $args );
?>
<!-- The Loop -->
<?php
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
$terms_slugs_string = '';
$terms = get_the_terms( $post->ID, 'my_post_type' );
if ( $terms && ! is_wp_error( $terms ) ) {
$term_slugs_array = array();
foreach ( $terms as $term ) {
$term_slugs_array[] = $term->slug;
}
$terms_slugs_string = join( " ", $term_slugs_array );
}
?>
<div class="box<?php echo $terms_slugs_string ?>">
<div class="port-item-home">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'portfolio-home' ); ?>
</a>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
</div>
<?php endwhile; ?>
ok I have a portfolio page. Every portfolio item has thumbnail attached. what I want is to print out the first thumbnail from the first post twice. One at the beginning & other at the ending. like: image_1, image_2, image_3, image_4 & then image_1 again.
my code is:
<div class="main-interior portfolio" id="portfolio-big-pics" style="display: block;">
<?php $args = array( 'post_type' => 'portfolio', 'order' => 'dsc');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $extraFirstClass = $loop->current_post == '0' ? ' main-image-porfolio-main' : ''; ?>
<?php
$attributes = array(
"class" => "main-image portfolio " . $extraFirstClass,
"id" => "photo_{$post->ID}",
);
the_post_thumbnail("portfolio_thumb", $attributes);
?>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<div class="portfolio-box">
<h5>Portfolio</h5>
<ul class="item-list" id="portfolio-list">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li><?php the_title(); ?>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
How can I do it?
As previously answered by me here, I would use PHP for. However, if for some reason you don't want that, I don't think you would need to resort to two loops for this. You can do the following:
<?php
$args = array( 'post_type' => 'portfolio', 'order' => 'dsc');
$loop = new WP_Query( $args );
$first = $loop->posts[0];
$attributes = array(
"class" => "main-image portfolio",
"id" => "photo_{$loop->posts[$i]->ID}",
);
<div class="main-interior portfolio" id="portfolio-big-pics" style="display: block;">
for( $i = 0; $i < count($loop->posts); $i++ ) {
$attrs = $attributes;
$attrs["class"] .= $i === 0 ? ' main-image-portfolio-main' : '';
echo get_the_post_thumbnail( $loop->posts[$i]->ID, "portfolio_thumb", $attrs );
}
echo get_the_post_thumbnail( $first->ID, "portfolio_thumb", $attrs );
?>
<div class="portfolio-box">
<h5>Portfolio</h5>
<ul class="item-list" id="portfolio-list">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
<li>
<?php echo $first->post_title;?>
</li>
</ul>
</div>
</div>
here is the code, edit it according to your needs:
$(document).ready(function()
{
var imagesrc = $(".example post's image class").attr("src");
$(".the container or post after which you want to put your image").appendTo("<img src='"+imgsrc+"' alt='image' />");
});
Hi i have this template in wordpress, i would like to just display 10 items, because right now in general options in wordpress i have 5 items but i would like to make an exception with this template i dont know where i have to modify the code in order to show in this template 10 items:
<?php
/*
Template Name: Blog List
*/
?>
<?php get_header(); ?>
<div class="content-wrap">
<div class="content">
<?php tie_breadcrumbs() ?>
<div id="content" class="podcast_archive">
<!--<div class="podcast_full">-->
<?php if ( have_posts() ) : ?>
<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<h1><?php _e( 'El Jurado del Pueblo' , 'ss-podcasting' ); ?></h1>
</header>
<?php
$feed_url = trailingslashit( home_url() ) . '?feed=podcast';
$custom_feed_url = get_option('ss_podcasting_feed_url');
if( $custom_feed_url && strlen( $custom_feed_url ) > 0 && $custom_feed_url != '' ) {
$feed_url = $custom_feed_url;
}
$itunes_url = str_replace( array( 'http:' , 'https:' ) , 'itpc:' , $feed_url );
?>
<section>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post(); ?>
<?php
$terms = wp_get_post_terms( get_the_ID() , 'series' );
foreach( $terms as $term ) {
$series_id = $term->term_id;
$series = $term->name;
break;
}
?>
<article class="podcast_episode">
<?php if( has_post_thumbnail() ) { ?>
<?php $img = wp_get_attachment_image_src( get_post_thumbnail_id() ); ?>
<a>" title="<?php the_title(); ?>">
<?php the_post_thumbnail( 'podcast-thumbnail' , array( 'class' => 'podcast_image' , 'alt' => get_the_title() , 'title' => get_the_title() ) ); ?>
</a>
<?php } ?>
<h3>
<strong><?php the_title(); ?></strong>
<div class="podcast_meta"><?php echo $series; ?><aside></div>
</h3>
<div id="audio">
<?php global $ss_podcasting;
$enclosure = $ss_podcasting->get_enclosure( get_the_ID() );
if( $enclosure ) {
$audio_player = $ss_podcasting->audio_player( $enclosure );
echo $audio_player;
} ?>
<?php the_content(); ?>
</div>
<div id="audioinfo">
<a>">Descargar Audio</a>
<span class="audiometa">
Tamaño: <?php echo get_post_meta(get_the_ID(), 'filesize', true) ?>
</span>
</div>
<?php echo do_shortcode('[divider]');?>
</article>
<?php
endwhile;
?>
</section>
<?php endif; ?>
<?php wp_pagenavi(); ?>
<div class="podcast_clear"></div>
</div>
<?php comments_template( '', true ); ?>
</div><!-- .content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
?>
i would some advise so i can do it by myself :)
thank you very much
You'll want to use the query_posts() function for that, just before your loop.
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'showposts' => '10' ) );
query_posts( $args );
http://codex.wordpress.org/Function_Reference/query_posts
You'd need to modify your template's query. I'd suggest making use of the WP_Query class. For example:
$args = array(
'posts_per_page' => 10
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
// Loop item here
}
wp_reset_postdata();
} else {
// No results found
}
if
$args = array(
'posts_per_page' => 10
);
not work than check at back-end under Setting->Reading there is a "Blog pages show at most" if there is 5 post than it display only 5 post.