To start with I kept getting the results from the ‘media-coverage’ category when I tried a different way and now nothing seems to work – just blank all the time.
Here is the code now:
<?php if ( ! is_page( 'press-releases' || 'media-coverage' )) { ?>
<div class="col-xs-12 col-md-9">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
endwhile;
?>
</div>
<?php } ?>
<?php if ( is_page( 'press-releases' )) { ?>
<div class="col-xs-12 col-md-9">
<h1>Press Releases</h1>
<?php
$query = new WP_Query( array( 'category_name' => 'press-release' ) );
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_postdata();
?>
</div>
<?php } ?>
<?php if ( is_page( 'media-coverage' )) { ?>
<div class="col-xs-12 col-md-9">
<h1>Media Coverage</h1>
<!-- another query will need to be here for Media Coverage articles -->
</div>
<?php } ?>
]]><?
$catid = get_cat_id( single_cat_title("",false) );;
$args = array(
'cat' => '$catid',
'post_type' => 'post',
'meta_key' => 'MY_KEY',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
query_posts( $args );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><br /><?php
endwhile;
endif;
wp_reset_query();
?>
]]><?php
if (is_home()) {
query_posts(“cat=-6”);
}
?>
Necesito saber como poder filtrar una query que viene devuelta en archive.php para poder mostrar por un lado, n post de una categoria sobre el resto de post.
Actualmente mi archivo php tiene el siguiente codigo:
` <?php if (have_posts()) : $post = $posts[0]; while (have_posts()) : the_post();?>
<div id=”contents-wrapper” class=”hideOnSearch”>
<div class=”contents”>
<div class=”thumb_results”><a href=”<?php the_permalink();?>”><?php gorilla_img(‘medium’);?></a></div>
<div class=”result-detail-wrapper”> <!– result detail wrapper –>
<h2><a class=”result-page-title” href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a></h2><br/>
<?php echo mb_substr( strip_tags( $post->post_content ),0,235) . ‘…’;?><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”Permanent Link to <?php echo $post->post_title ?>”><?php _e(‘read more.’,’language’);?></a><div style=”clear:both”></div>
</div> <!– result detail wrapper ends –>
</div><!– end of .contents –>
</div><!– end of #content-wrapper –>
<?php endwhile; else: ?>
<div class=”no-results”>
<p><strong><?php _e(‘No Results Found.’,’language’);?></strong></p>
</div><!– .no-results ends –>
<?php endif;?>
<div style=”clear:both”></div>
<?php theme_pagination( $wp_query->max_num_pages); ?>
</div><!– end of #two-columns –> `
Pero quiero primero poner los que se refieren a “cat=6” y luego lista rlos demas sin la cat=6. el problema que tengo es que si capturo cn wp_query al venis de una opción de menu de categoria pierde ese filtro y me muestra todos el contenido
I am working on the page https://kraftwerkk9.com/news. The pagination is not working in that if you try to go to a new page, it just displays the first page of posts in that category.
I have narrowed the problem down to the use of `<?php
query_posts(‘cat=1’);
?>` in the template file. If I remove that bit, it shows all post and pagination works. How do I display category 1 without the use of query_post?
Here is the entirety of the code in that file:
<?php
/**
* @package WordPress
* @subpackage Grid_Focus
*/
get_header();
?>
<div id="filler" class="fix">
<div id="mainColumn">
<h2 class="page_title">News</h2>
<?php
query_posts('cat=1');
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="post">
<div class="postMeta">
<p class="container">
<span class="date"><?php the_time('M j, Y') ?></span>
<span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span>
</p>
</div>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h2>
<div class="addthis_toolbox addthis_default_style" style="">
<a class="addthis_button_facebook_send" addthis:url="<?php the_permalink(); ?>" addthis:title="<?php the_title(); ?>" ></a>
<a class="addthis_button_tweet" addthis:url="<?php the_permalink(); ?>" addthis:title="<?php the_title(); ?>" tw:via="kraftwerkk9"></a>
<a class="addthis_button_google_plusone" g:plusone:annotation="bubble" addthis:url="<?php the_permalink(); ?>" addthis:title="<?php the_title(); ?>"g:plusone:size="medium" ></a>
<div class="hide_fb_like"><a class="addthis_button_facebook_like" addthis:url="<?php the_permalink(); ?>" ></a></div>
</div>
<br clear="all"/>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="post">
<div class="postMeta">
<p class="container">
<span class="date">No Matches</span>
</p>
</div>
<h2>No matching results</h2>
<div class="entry">
<p>You seem to have found a mis-linked page or search query with no matching results. Please trying your search again. If you feel that you should be staring at something a little more concrete, feel free to email the author of this site or browse the archives.</p>
</div>
</div>
<?php endif; ?>
<?php if(function_exists('wp_paginate')) {
wp_paginate();
} ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
]]><div id="headline" class="left">
<?php query_posts("showposts=1&category_name=Especiales"); ?>
<?php while (have_posts()) : the_post(); ?>
<h3 class="cat_title"> <?php the_category(', '); ?> »</h3>
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="meta"><?php the_time('j M Y') ?> | <?php comments_popup_link('<div class="genericon genericon-chat"></div> +', '<div class="genericon genericon-chat"></div> 1', '<div class="genericon genericon-chat"></div> %');?></div>
<?php $values = get_post_custom_values("Image");?>
<a class="left" href="<?php the_permalink() ?>" rel="bookmark" title="Enlace a <?php the_title(); ?>">
<img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
$values = get_post_custom_values("Image"); echo $values[0]; ?>&w=250&h=200&zc=1&q=100"
alt="<?php the_title(); ?>" class="left" width="250px" height="200px" /></a>
<?php the_excerpt(); ?>
<a class="left" href="<?php the_permalink() ?>" rel="bookmark" title="Enlace a <?php the_title(); ?>">Leer más »</a>
<?php endwhile; ?>
</div>
<div id="headline" class="right">
<?php query_posts("showposts=1&excludeposts=1&orderby=rand&category_name=Especiales"); ?>
<?php while (have_posts()) : the_post(); ?>
<h3 class="cat_title"> <?php the_category(', '); ?> »</h3>
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="meta"><?php the_time('j M Y') ?> | <?php comments_popup_link('<div class="genericon genericon-chat"></div> +', '<div class="genericon genericon-chat"></div> 1', '<div class="genericon genericon-chat"></div> %');?></div>
<?php $values = get_post_custom_values("Image");?>
<a class="left" href="<?php the_permalink() ?>" rel="bookmark" title="Enlace a <?php the_title(); ?>">
<img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
$values = get_post_custom_values("Image"); echo $values[0]; ?>&w=250&h=200&zc=1&q=100"
alt="<?php the_title(); ?>" class="left" width="250px" height="200px" /></a>
<?php the_excerpt(); ?>
<a class="left" href="<?php the_permalink() ?>" rel="bookmark" title="Enlace a <?php the_title(); ?>">Leer más »</a>
<?php endwhile; ?>
</div>
]]>At the moment I’m using this code:
<?php query_posts('cat=3&tag=test&orderby=rand&showposts=6'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
It doesn’t work as expected…it only shows results if I use “cat” or “tag” but not in combination…
I’m not sure if query_post() is the best solution in order to filter posts that have a combination of “cat” AND “tag”.
What do you suggest?
Thanks in advance for your help.
]]>je souhaite afficher tout les articles sur une page autre(blog.php) que index.php. Mais je n’y arrive pas! Il n’y a que les 10 premiers articles qui s’affiche. Le lien des pages suivante ne fonctionne pas non plus! pourquoi ?
J’ai testé de mettre le code de la page index.php ( qui lui affiche tout les articles sur index.php) sur ma page blog.php mais cela ne fonctionne pas!
voici mon code de ma page blog.php qui n’affiche que 10 articles :
get_header(blog); ?>
<div id=”primary” class=”content-area”>
<div id=”content” class=”site-content” role=”main”>
<?php wp_list_categories( ‘hide_empty=0’ ); ?> <!– affiche les catégories –>
<?php query_posts(‘order=DESC’); ?>
<?php while (have_posts()) : the_post(); ?>
<p><?php the_time(‘d/m/Y’); ?></p>
<h3>” title=”Lire : <?php the_title(); ?>”><?php the_title(); ?></h3>
<?php endwhile; ?>
<?php posts_nav_link(‘ · ‘, ‘page précédente’, ‘page suivante’); ?>
<!– affiche navigation page suivante/page précédente –>
<?php wp_reset_query(); ?>
</div><!– #content –>
</div><!– #primary –>
Merci d’avance
]]><?php get_header(); ?>
<!--Start Content Wrapper-->
<div class="content_wrapper">
<div class="grid_16 alpha">
<div class="featured_content">
<h1>
<?php
$sfrom = $_REQUEST['sfrom'];
$location = $_REQUEST['location'];
if ($sfrom !== "" && $location == "") {
printf(__(U_SRC_FR . ' %s', THEME_SLUG), '' . $sfrom . '');
} elseif ($sfrom == "" && $location !== "") {
printf(__(NEAR . ' %s', THEME_SLUG), $location);
} elseif ($sfrom !== "" && $location !== "") {
printf(__(U_SRC_FR . ' %s ' . NEAR . ' %s', THEME_SLUG), '' . $sfrom . '', $location);
}
?>
</h1>
<?php
$results = gc_multi_search($sfrom, $location);
if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
} else { // If the pn URL variable is not present force it to be value of page number 1
$pn = 1;
}
$itemsPerPage = get_option('posts_per_page');
$lastPage = ceil($results['query'] / $itemsPerPage);
if ($pn < 1) { // If it is less than 1
$pn = 1; // force if to be 1
} else if ($pn > $lastPage) { // if it is greater than $lastpage
$pn = $lastPage; // force it to be $lastpage's value
}
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= '<li><a class="current" href="">' . $pn . '</a></li>';
$centerPages .= '<li> <a href="' . site_url(GC_SEARCH . "/?pn=$add1&sfrom=$sfrom&location=$location") . '">' . $add1 . '</a></li>';
} else if ($pn == $lastPage) {
$centerPages .= '<li> <a href="' . site_url(GC_SEARCH . "/?pn=$sub1&sfrom=$sfrom&location=$location") . '">' . $sub1 . '</a></li>';
$centerPages .= '<li><a class="current" href="">' . $pn . '</a></li>';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
$centerPages .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$sub2&sfrom=$sfrom&location=$location") . '">' . $sub2 . '</a></li>';
$centerPages .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$sub1&sfrom=$sfrom&location=$location") . '">' . $sub1 . '</a></li>';
$centerPages .= '<li><a class="current" href="">' . $pn . '</a></li>';
$centerPages .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$add2&sfrom=$sfrom&location=$location") . '">' . $add1 . '</a></li>';
$centerPages .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$add2&sfrom=$sfrom&location=$location") . '">' . $add2 . '</a></li>';
} else if ($pn > 1 && $pn < $lastPage) {
$centerPages .= '<li> <a href="' . site_url(GC_SEARCH . "/?pn=$sub1&sfrom=$sfrom&location=$location") . '">' . $sub1 . '</a> </li>';
$centerPages .= '<li><a class="current" href="">' . $pn . '</a></li>';
$centerPages .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$add1&sfrom=$sfrom&location=$location") . '">' . $add1 . '</a></li>';
}
$limit = 'LIMIT ' . ($pn - 1) * $itemsPerPage . ',' . $itemsPerPage;
$paginationDisplay = "<ul class='paginate'>"; // Initialize the pagination output variable
if ($lastPage != "1") {
//$paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage . ' ';
if ($pn != 1) {
$previous = $pn - 1;
$paginationDisplay .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$previous&sfrom=$sfrom&location=$location") . '">«</a></li>';
}
$paginationDisplay .= $centerPages;
if ($pn != $lastPage) {
$nextPage = $pn + 1;
$paginationDisplay .= '<li><a href="' . site_url(GC_SEARCH . "/?pn=$nextPage&sfrom=$sfrom&location=$location") . '">»</a></li> ';
}
}
$paginationDisplay .= '</ul>';
if($pn < 1){
$paginationDisplay = '';
}
$results = gc_multi_search($sfrom, $location, $limit);
if ($results['result']) {
foreach ($results['result'] as $q) {
$featured_class = '';
$is_pro = get_post_meta($q->ID, 'geocraft_listing_type', true);
if ($is_pro == 'pro') {
$featured_class = 'featured';
}
$img_meta = get_post_meta($q->ID, 'geocraft_meta_image1', true);
?>
<!--Start Featured Post-->
<div class="featured_post">
<div class="<?php echo $featured_class; ?>">
<!--Start Featured thumb-->
<div class="featured_thumb">
<?php if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) { ?>
<?php inkthemes_get_thumbnail(128, 108, '', $img_meta); ?>
<?php } else { ?>
<?php search_get_image(128, 108, '', $img_meta, get_permalink($q->ID)); ?>
<?php
}
?>
<?php if ($is_pro == 'pro') { ?>
<img class="ribbon" src="<?php echo get_template_directory_uri(); ?>/images/ribbon.png"/>
<?php } ?>
<ul class="star_rating">
<?php
echo geocraft_get_post_rating_star($q->ID);
?>
</ul>
<span class="review_desc"><?php gc_comments_popup_link($q->ID,N_RV, _RV, '% ' . REVIEW); ?></span> </div>
<!--End Featured thumb-->
<div class="f_post_content">
<h4 style="margin-bottom: 3px !important;" class="f_post_title"><a href="<?php echo get_permalink($q->ID); ?>" rel="bookmark" ><?php echo get_the_title($q->ID); ?></a></h4>
<?php if (get_post_meta($q->ID, 'geo_address', true)): ?>
<p class="f_post_meta"><img src="<?php echo TEMPLATEURL . '/images/location-icon.png'; ?>"/> <?php echo get_post_meta($q->ID, 'geo_address', true); ?></p>
<?php endif; ?>
<?php
$excerpt = preg_replace("/<img[^>]+\>/i", "", $q->post_content);
$excerpt = substr(strip_tags($excerpt), 0, 111);
printf("%s", $excerpt);
if (strlen($excerpt) > 110)
echo ' <a href="' . get_permalink($q->ID) . '">' . '[...] Read More' . '</a>';
?>
</div>
</div>
</div>
<!--End Featured Post-->
<?php
}
}else {
?>
<div class = "featured_post">
<p class = "place"><?php echo NO_LST_FND; ?></p>
</div>
<?php
}
?>
<div class="paging"><span style="float:right;"><?php echo $paginationDisplay; ?></span></div>
</div>
</div>
<div class="grid_8 omega">
<?php
global $post;
get_sidebar(POST_TYPE);
?>
</div>
</div>
<!--End Content Wrapper-->
<?php get_footer(); ?>
Above is my search.php file.
My post type is = listing
meta key = geocraft_listing_type
meta_value are pro and free
I want this above search – as pro value first then free with random.
]]>function gc_multi_search( $sfrom, $location, $limit = null ) {
global $wpdb;
if ( !empty( $sfrom ) || !empty( $location ) )
$n = ‘%’;
$post_type = POST_TYPE;
$post_status = ‘publish’;
$meta_key = “geo_address”;
$query = ”;
if ( $sfrom !== ” && $location == ” ) {
$query = “SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->term_relationships
ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy
ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
INNER JOIN $wpdb->terms
ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id
WHERE post_status = ‘$post_status’ AND post_type = ‘$post_type’ AND
(post_title LIKE ‘{$n}$sfrom{$n}’ OR post_content LIKE ‘{$n}$sfrom{$n}’ OR $wpdb->terms.name = ‘$sfrom’) GROUP BY $wpdb->posts.ID {$limit}”;
} elseif ( $sfrom == ” && $location !== ” ) {
$query = “SELECT *
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
WHERE post_status = ‘$post_status’ AND post_type = ‘$post_type’ AND
(meta_key = ‘$meta_key’ AND meta_value like ‘{$n}$location{$n}’)
GROUP BY $wpdb->posts.ID {$limit}”;
} elseif ( $sfrom !== ” && $location !== ” ) {
$query = “SELECT $wpdb->posts.*
FROM
$wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
INNER JOIN $wpdb->term_relationships
ON $wpdb->term_relationships.object_id = $wpdb->posts.ID
INNER JOIN $wpdb->term_taxonomy
ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
INNER JOIN $wpdb->terms
ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id
WHERE post_status = ‘$post_status’ AND post_type = ‘$post_type’ AND
(post_title like ‘{$n}$sfrom{$n}’ OR post_content like ‘{$n}$sfrom{$n}’ OR $wpdb->terms.name = ‘$sfrom’) AND
(meta_key = ‘$meta_key’ AND meta_value like ‘{$n}$location{$n}’)
GROUP BY $wpdb->posts.ID {$limit}”;
}
$results = array();
$results[‘result’] = $wpdb->get_results( $query );
$results[‘query’] = $wpdb->query( $query );
return $results;
}
above is my search function.
my post type is = listing meta key = geocraft_listing_type meta_value pro and free so i want this above search function as pro value first then free with random.
and right now as per function it came with id. and if i add after group by ASC and DESC then it will work .but i want pro value first then free.. thanks.
waiting for your reply thanks