please can someone tell me how to alphabetize this?
I've tried quite a few things and nothing seems to work.
<?php query_posts( array('post__not_in' => array(46,2401), 'cat' => $category_id,'posts_per_page'=>'-1')); ?>
<?php while ( have_posts() ) : the_post();
echo '<li';
if (($ID = get_the_ID()) == $pagepostid) echo ' class="proadv-current-item"';
//else echo ' class="post-id'.$ID.'-id'.$pagepostid.'"';
echo '>';
echo '<div class="sponsor-thumb">';
echo '<a href="'.get_permalink().'">';
the_post_thumbnail( 'category-thumb' );
echo '</a>';
echo '</div>';
echo '<a href="'.get_permalink().'">';
the_title();
echo '</a>';
echo '</li>';
endwhile; ?>
<?php wp_reset_query(); ?>
Try specifying orderby in args array:
query_posts( array('post__not_in' => array(46,2401), 'cat' => $category_id,'posts_per_page'=>'-1','orderby'=>'name','order'=>'ASC'));
Related
I have a code in my page.php file that creates a list of child pages. I want every li to have a background-image added by Featured image function. Here is the entire code I have
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
<?php
if (is_page('eventsphotography')) {
$query = new WP_query('pagename=eventsphotography');
$eventsphotography_id = $query->queried_object->ID;
//The loop
if($query->have_posts() ) {
while($query->have_posts() ) {
$query->the_post();
the_content();
}
}
/* Get the children of the eventsphotography page */
$args = array (
'post_parent' => $thePostID,
'post_parent' => $eventsphotography_id,
'order' => 'ASC'
);
$eventsphotography_query = new WP_query($args);
//The Loop
if($eventsphotography_query->have_posts() ) {
echo '<ul class="events-list">';
while($eventsphotography_query->have_posts() ){
$eventsphotography_query->the_post();
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
echo '<li style="background:url(' . $background[0] . '); background-repeat:no-repeat; background-size:cover;">';
echo '<div class="events-centered">';
echo '<a href="' . get_permalink() . '">';
echo '<h4>' . get_the_title() . '</h4>';
echo '</a>';
echo '<div class="view-events-details">';
echo '<a href="' . get_permalink() . '">';
echo '<h5>View Images</h5>';
echo '</a>';
echo '</div>';
echo '</div>'; /* end of events-centered */
echo '</li>';
}
echo'</ul>';
}
}
?>
I only need help for these lines:
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
AND
echo '<li style="background:url(' . $background[0] . '); background-repeat:no-repeat; background-size:cover;">';
Here's the screenshot of the result of my code:
http://oi68.tinypic.com/10xzdhl.jpg
I marked the first <li> with a red rectangle. As I said before, I want URL of the featured image to be placed in <li style="background:url(URL of the featured image)">
I have found a solution. First, I created a new WP_Query:
$subs = new WP_Query( array( 'post_parent' => $post->ID, 'post_type' => 'page', 'meta_key' => '_thumbnail_id'));
Then in my loop I added this lines:
if($eventsphotography_query->have_posts() && $subs->have_posts()) {
echo '<ul class="events-list">';
while($eventsphotography_query->have_posts() && $subs->have_posts()){
$eventsphotography_query->the_post();
$subs->the_post();
echo '<li>';
echo get_the_post_thumbnail($post->ID);
...rest of the code...
<div class="page-content">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<?php the_title(); ?>
<br />
<?php
the_content();
echo get_the_date('l,d');
endwhile;
endif;
?>
</div>
This example is not repeating the date for each post. I am using the code in a page template, namely services-template.php and I have read the note that states get_the_date() will repeat the date for each post. Can someone help me figure out what I am doing wrong?
I could not make the original code work, I do not know all the internal workings of Wordpress but my guess is that what ever variable holds post data (most likely $post) was empty. The following code did what I was looking to do. Again I am using this code on a custom page. services-template.php.
$args = array( 'category' => '4' );
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li><h2>' . get_the_title() . '</h2></li>';
echo '<li>' . get_the_date() . '</li>';
echo '<li>' . get_the_excerpt() . '</li>';
the_tags();
echo '<br /><br />';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
;
?>
I have tried this code:
<?php
query_posts(array(
'meta_key' => 'custom_cat',
'meta_value' => 'creative',
'post_type' => 'page'
));
echo '<ul id="creative_services" class="clearfix row">';
if ( have_posts() ) while ( have_posts() ) : the_post();
echo '<li class="col-md-3">';
echo '<a class="popover-dismiss" data-toggle="popover" title="';
echo $post->post_title;
echo '" data-placement="bottom" data-content="';
echo $post->post_content;
echo '"><i class="';
get_post_meta( get_the_ID(), 'fa_icon' );
echo '"></i></a>';
echo '<h3>';
the_title();
echo '</h3>';
endwhile;
echo '</ul>';
wp_reset_query(); ?>
to display the custom field value as a class name, but the value is not displaying. Please help me find the problem or solution to display the custom field value as class name. I'm having hard time to debug this codes because i'm not a programmer, i'm a designer, still in the process of exploring wordpress.
Try adding echo before get_post_meta( get_the_ID(), 'fa_icon' );
so it would be:
<?php
query_posts(array(
'meta_key' => 'custom_cat',
'meta_value' => 'creative',
'post_type' => 'page'
));
echo '<ul id="creative_services" class="clearfix row">';
if ( have_posts() ) while ( have_posts() ) : the_post();
echo '<li class="col-md-3">';
echo '<a class="popover-dismiss" data-toggle="popover" title="';
echo $post->post_title;
echo '" data-placement="bottom" data-content="';
echo $post->post_content;
echo '"><i class="';
echo get_post_meta( get_the_ID(), 'fa_icon' );
echo '"></i></a>';
echo '<h3>';
the_title();
echo '</h3>';
endwhile;
echo '</ul>';
wp_reset_query(); ?>
I have this code in my wordpress. Is in the collection.php
This code makes rows when there are 3 posts and when there are 3 posts the closes.
When I have 3, 6 or 9 posts works fine but the problem is when I have 4 or 5 posts because the doesn't close and the code stays open.
Anyone can help me. I appreciate this very much.
Regards
$i = 0;
if ( have_posts() ) : while ( have_posts() ) : the_post();
$i++;
if($i%3 == 1){echo '<div class="row">'; }
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<div class="col-md-4">';
echo '<a href="';
echo the_permalink();
echo '">';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '</a>';
echo '<h3 class="category-title"><a href="';
echo the_permalink();
echo '">';
echo the_title();
echo '</a></h3>';
echo '</div>';
}
}
if($i%3 == 0){echo '</div>';}
endwhile; endif;
if($i%3 == 0){echo '</div>';}
endwhile; endif;
change to :
if($i%3 == 0){echo '</div>';}
endwhile; endif;
if($i%3 != 0){echo '</div>';}
I have the following code:
<?php
query_posts(array(
'posts_per_page' => -1,
'post_type' => 'sample-letter',
'order' => 'ASC'
));
while(have_posts()){
the_post();
echo '<div class="col-md-9"><span class="title">title</span><br />';
}
wp_reset_query();
?>
It works great but the problem is, I can't use:
<?php the_permalink() ?>
INSIDE the echo statement. It is a simple link, and rather than render the link url, it outputs:
http://sitename.com/<?php the_permalink() ?>
Instead of:
http://sitename.com/thelink
How can I make this loop work without the echo? Is that actually the problem at all?
Use the echo part like;
echo '<div class="col-md-9"><span class="title">title</span><br />';
or you can use;
$current_post_id = get_the_ID(); // id of current post in the loop
$permalink = get_permalink( $current_post_id );
$title = get_the_title( $current_post_id );
echo '<div class="col-md-9"><span class="title">' . $title . '</span><br />';