<ul class="slides">
<?php
$slide = get_option('cany_slide_cat');
$count = get_option('cany_slide_count');
$slide_query = new WP_Query( 'category_name='.$slide.'&posts_per_page='.$count.'' );
while ( $slide_query->have_posts() ) : $slide_query->the_post();
$do_not_duplicate[] = $post->ID
?>
<li>
<img class="slideimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php echo get_image_url()?>&h=300&w=650&zc=1" title="" alt="" />
<div class="flex-caption">
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
</li>
<?php endwhile; ?>
</ul>
I want to have post title instead of post text on my wordpress slider, but when im changing the_post to the_title something goes wrong.
My web-page is: http://soccerway.ge/
Thank you in advance
You can do that by updating;
<div class="flex-caption">
<?php wpe_excerpt('wpe_excerptlength_slide', ''); ?>
</div>
to
<div class="flex-caption">
<?php the_title( '<h2>', '</h2>' ); ?>
</div>
This will put current post title to each post
Related
The image is set to return a URL in the Custom Fields Plugin however it is just coming up with img src Unknown, everything else works on the page except this... code is as follows: Thanks in advance for any help!
<?php get_header(); ?>
<?php
$args = array(
'post_type' => 'artists',
);
$query = new WP_Query( $args );
?>
<section class="row artists">
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-sm-12 col-md-6 col-lg-3">
<a href="<?php if( get_post_field('artist_website') ) { ?>
<?php echo $artist_website; ?>
<?php } else { the_permalink(); } ?>">
<img src="<?php get_post_field('artist_feature_image'); ?>" alt="<?php echo the_title() ; ?>">
<p><?php echo the_title() ;?></p>
</a>
</div>
<?php endwhile; endif; wp_reset_postdata(); ?>
</section>
<?php get_footer(); ?>
The problem is that get_post_field('artist_feature_image') only return the image.
You need to display it with "echo"
<img src="<?php echo get_post_field('artist_feature_image'); ?>" />
And don't do echo the_title() ;, because the_title() is already doing an echo on get_the_title();
function the_title() {
echo get_the_title();
}
So if you want to display it you just have to do: the_title();
I am creating a news centre which pulls in the newest wordpress post, of a specified category. It includes the post image and title. The div group has a hover animation, and i want that class, when clicked, to link to the post its pulling the title and image from.
Currently it only links if you click on the title itself, i want to be able to click the entire block and it link to the post. Any ideas? here is the code as it stands...
<?php query_posts('cat=1 &posts_per_page=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="block-1">
<div class="news-center-overlay transition">
<p>VIEW FULL STORY</p>
<div id="news-line-box">
<div id="part-1"></div><div id="part-2"><img src="<?php echo get_stylesheet_directory_uri()?>/img/star.png"/> </div><div id="part-3"></div>
</div>
<h4>COMETS BASKETBALL</h4>
</div>
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
<p class="news-center-title animation"><?php echo get_the_title( $ID ); ?></p>
</div>
<?php endwhile; endif; ?>
From my understanding, You are looking to click a Block with the link to the post that resides under the Block
If this is the case, The Block can be wrapped in a href link or the href link can be wrapped to the news-center-overlay class
<?php query_posts('cat=1 &posts_per_page=1'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="block-1">
<div class="news-center-overlay transition">
<p>VIEW FULL STORY</p>
<div id="news-line-box">
<div id="part-1"></div><div id="part-2"><img src="<?php echo get_stylesheet_directory_uri()?>/img/star.png"/> </div><div id="part-3"></div>
</div>
<h4>COMETS BASKETBALL</h4>
</div>
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
<p class="news-center-title animation"><?php echo get_the_title( $ID ); ?></p>
</div>
</a>
<?php endwhile; endif; ?>
I have try all the functions related to print categories that the codex provide, but i havent found any way that works for me.
Im trying to print the categories slug for put it inside a class.
I want to print the category of the actual post in div with the class proyect, so then i can use it to filter with isotope.
<!-- feature posts -->
<div id="container">
<?php $the_query = new WP_Query('showposts=5&orderby=post_date&order=DESC'); ?>
<?php while ($the_query->have_posts()) : $the_query->the_post();
$id = get_the_ID(); ?>
<div class="proyect <?php wp_get_post_categories($id); ?>">
<div class="view view-tenth">
<a style="display:block;" href="<?php the_permalink(); ?>">
<article> <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail('', array("class" => "")); } ?></article>
</a>
<div class="mask">
<h2><?php echo substr(strip_tags(get_the_title()),0,35); ?></h2></a>
<p class="fecha-post"><?php the_time('F j, Y'); ?></p>
<?php echo substr(strip_tags(get_the_content()),0,100); ?>
<a class="info" href="<?php the_permalink(); ?>">Ver más...</a>
</div>
</div>
</div>
<?php endwhile;?>
</div>
<!-- #feature post -->
From http://wordpress.org/support/topic/getting-category-slug-from-posts-in-the-loop:
<li class="<?php foreach(get_the_category() as $category) { echo $category->slug . ' ';} ?>">
You should be able to use:
$cats = wp_get_post_categories($post->ID);
This will be an array of the categories associated with this post. Then you can loop through them and do whatever you need.
I have managed to get recent posts showing on my homepage which is working well. They only problem i have is that the full post and not the excerpt is showing.
<div id="home-news-container">
<?php query_posts('cat=#&posts_per_page=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="home-post-container">
<div class="home-post-thumb">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail('large_wide'); ?>
</a>
</div>
<div class="home-post-copy">
<h4>
<a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
</a>
</h4>
<h5>
<?php the_date(); ?>
</h5>
<?php echo the_excerpt(); ?>
<div class="home-news-readmore">
read more
</div>
</div>
</div> <!-- end home-post-container -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<div class="home-news-readmore news-extra">
more news
</div>
</div> <!--- end home-post-container -->
I don't understand what the problem is to be honest. I created a new full width template for the homepage which i thought might be causing it but its not. Bit stumped to be honest. Any help would be greatly appreciated
Use wp_get_recent_posts to get recent post
Use substr to display some limeted character of post character
<?php
$args = array (
'numberposts' => 3,
'post_type' => 'your post type name'
);
// the query
$recent_posts = new wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li>' . $recent["post_title"].' </li> ';
echo substr($recent["post_content"],0,100);
}
?>
I am trying to pull the first image from any new posts to my slider but having one hell of a time trying to get it to work right this is what I have so far
<div id="anicontainer">
<div id="aninav">
<ul>
<li id="featuredtab"> </li>
<li id="latesttab"> </li>
<li id="populartab"> </li>
</ul>
</div>
<!-- Sub Menus container. Do not remove -->
<div id="ani_inner">
<div id="featuredouter" class="innercontent">
<div id="featured" >
<ul class="ui-tabs-nav">
<?php
$ani_featured_slide = get_option('x12_featured_slide');
$my_query = new WP_Query("cat=".$ani_featured_slide."&showposts=5");
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li class="ui-tabs-nav-item" id="nav-fragment-<?php the_ID(); ?>"><img src="<?php bloginfo('template_url'); ?>/thumb.php?src=<?php echo catch_that_image() ?>&w=50&h=44&zc=1&q=100" alt="" /></li>
<?php endwhile; ?>
</ul>
<?php $my_query = new WP_Query("cat=".$ani_featured_slide."&showposts=5");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<!-- Slide Content -->
<div id="fragment-<?php the_ID(); ?>" class="ui-tabs-panel" style="">
<img src="<?php bloginfo('template_url'); ?>/thumb.php?src=<?php echo catch_that_image() ?>&w=368&h=256&zc=1&q=100" alt="" />
<div class="info" >
<h2><?php the_title(); ?></h2>
<p><?php ani_content_limit(150, "Read More →"); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<div id="latest" class="innercontent">
<?php $recent = new WP_Query("showposts=6"); while($recent->have_posts()) : $recent->the_post();?>
<div class="latestpost">
<?php if( get_post_meta($post->ID, "postimage", true) ): ?>
<img src="<?php bloginfo('template_url'); ?>/thumb.php?src=<?php echo catch_that_image() ?>&w=70&h=70&zc=1&q=100" class="latestpostimage" alt="<?php the_title(); ?>" />
<?php else: ?>
<img class="latestpostimage" src="<?php bloginfo('template_url'); ?>/images/postimage.png" alt="<?php the_title(); ?>" /><?php endif; ?><h2><?php the_title(); ?></h2>
<div class="shortstory">
<?php ani_content_limit(55, "Read More →"); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<div id="popular" class="innercontent">
<div id="populartags"><ul><li>
<?php wp_tag_cloud('smallest=9&largest=25&number=40'); ?>
</li>
</ul>
</div>
</div>
Any my function for grabbing the image is this
<?php function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
?>
Am new to php most of this was from google :(
If anyone can see a problem it would mean alot to me cheers
Have you considered using WordPress featured images? It would be much easier to set up for what you are trying to achieve...
In your theme's functions.php file:
add_theme_support( 'post-thumbnails' ); // add theme support
add_image_size( 'slide', 368, 256, true ); // add an image size
See http://codex.wordpress.org/Function_Reference/add_theme_support and http://codex.wordpress.org/Function_Reference/add_image_size for more info on these
Then you would have inside the loop something like:
<?php if(has_post_thumbnail()) {
the_post_thumbnail( 'slide' );
} else {
// no image found
} ?>
More info on this can be found here: http://codex.wordpress.org/Function_Reference/has_post_thumbnail and here: http://codex.wordpress.org/Function_Reference/the_post_thumbnail