I'm building my own website just for fun and for learning.
I want to display only the post with a certain category # my homepage.
I've tried a number of things but they don't seem to work
at my home.php
this is what te code looks like.
get_header(); ?>
<?php $blog_layout = get_theme_mod('blog_layout', 'small-images'); ?>
<?php if ( ($blog_layout == 'masonry') || ($blog_layout == 'fullwidth') ) {
$layout = 'fullwidth';
} else {
$layout = '';
} ?>
<?php if ( $blog_layout == 'masonry' ) {
$masonry = 'home-masonry';
} else {
$masonry = '';
} ?>
<div id="primary" class="content-area <?php echo $layout; ?>">
<main id="main" class="site-main" role="main">
<span class="diensten">ONZE DIENSTEN..</span>
<div class="diensten-content">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div class="home-wrapper <?php echo $masonry; ?>">
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ( $blog_layout == 'large-images' || $blog_layout == 'masonry' ) {
get_template_part( 'content', 'large' );
} else {
get_template_part( 'content', get_post_format() );
}
?>
<?php endwhile; ?>
</div>
<?php moesia_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!--diensten-content-->
<
</main><!-- #main -->
</div><!-- #primary -->
And at content.php
<article id="post-<?php the_ID(); ?>" <?php post_class(''); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<a href="<?php the_permalink(); ?>" class="H1-posts" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('moesia-thumb'); ?>
</a>
</div>
<?php endif; ?>
<?php if (has_post_thumbnail()) : ?>
<?php $has_thumb = ""; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="post-content <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<?php endif; ?>
</header><!-- .entry-header -->
<div class="entry-summary">
<?php if ( (get_theme_mod('full_content') == 1) && is_home() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
</div><!-- .entry-content -->
I've tried this..`
<?php
//refine your query to the category you desire either a slug(example below) or category id
$args = array(
'category_name' => 'my_category_slug',
);
//create the query using the arguments
$query = new WP_Query($args);
?>
//create the loop to show the posts
<?php if($query->have_posts()): ?>
<?php while($query->have_posts()): $query->the_post(); ?>
<h1><?php the_title(); ?></h1>
<div><?php the_content(); ?></div>
<?php endwhile; ?>
<?php endif; ?>
did not work. How do I fix this?`If It displays only the posts with a certain class if also good.
Thanks..
Related
So I'm building a website for my new business.
An I want to only run the following code if the post have a category of 'certain-category'.
How do I do this? I tried a number of things. but they do not work..``
<article id="post-<?php the_ID(); ?>" <?php post_class(''); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb">
<a href="<?php the_permalink(); ?>" class="H1-posts" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('moesia-thumb'); ?>
</a>
</div>
<?php endif; ?>
<?php if (has_post_thumbnail()) : ?>
<?php $has_thumb = ""; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="post-content <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<?php endif; ?>
</header><!-- .entry-header -->
<div class="entry-summary">
<?php if ( (get_theme_mod('full_content') == 1) && is_home() ) : ?>
<?php the_content(); ?>
<?php else : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
</div><!-- .entry-content -->
Use has_category()
if(has_category('certain-category', get_the_ID())):
// Do something
endif;
WordPress now has a native block which does this for you if you want the easy route the block is called Post and Page Grid it allows you to select what category of posts or pages it will show and you can select what information is shown e.g. Title, thumbnail, excerpt etc
I'm struggling to add new categories in search.php. But I failed. Actually the php file is beyond me. I need help :( I have 4 categories, location, sub-location, city and municipality. But these search codes use only titles. How can I add these categories in search.php file? Anybody can say the resolve please?
if( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'noo_property' ) :
?>
<?php
global $wp_query;
$show_map = noo_get_option('noo_property_listing_map',1);
$show_search = noo_get_option('noo_property_listing_search',1);
$disable_map = ( ! $show_map && $show_search ) ? ' disable_map="true"' : '';
$disable_search_form = ( $show_map && ! $show_search ) ? ' disable_search_form="true"' : '';
$search_layout = noo_get_option('noo_property_listing_map_layout','horizontal');
$advanced_search = ($show_search && noo_get_option('noo_property_listing_advanced_search',0)) ? ' advanced_search="true"' : '';
$title = __('Properties matching your search', 'noo');
?>
<?php get_header();
?>
<div class="container-wrap">
<?php if(!empty($show_map) || !empty($show_search)):?>
<?php echo do_shortcode('[noo_advanced_search_property style="'.$search_layout.'"' . $disable_map . $disable_search_form . $advanced_search . ']');?>
<?php endif;?>
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?>" role="main">
<?php if ( have_posts() ) : ?>
<?php
$args = array(
'query' => $wp_query,
'title' => $title,
'display_mode' => true,
'default_mode' => '',
'show_pagination' => true,
'ajax_pagination' => false,
'show_orderby' => noo_get_option('noo_property_listing_orderby', 1)
);
re_property_loop( $args ); ?>
<?php else : ?>
<?php noo_get_layout( 'no-content' ); ?>
<?php endif; ?>
<?php
wp_reset_query();
wp_reset_postdata();
?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php else :
?>
<?php get_header(); ?>
<div class="container-wrap">
<div class="main-content container-boxed max offset">
<div class="row">
<div class="<?php noo_main_class(); ?> <?php noo_page_class(); ?>" role="main">
<h1><?php _e('Results For', 'noo'); ?><span>"<?php the_search_query(); ?>"</span></h1>
<div id="search-results">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if( get_post_type($post->ID) == 'post' ){ ?>
<article class="result">
<div class="content-featured">
<?php noo_featured_content( $post->ID ); ?>
</div>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Blog Post', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'page' ){ ?>
<article class="result">
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Page', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php }
else if( get_post_type($post->ID) == 'product' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Product', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else if( get_post_type($post->ID) == 'noo_property' ){ ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''. get_the_post_thumbnail($post->ID, 'property-image', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?> <small><?php echo __('Property', 'noo'); ?></small></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } else { ?>
<article class="result">
<?php if(has_post_thumbnail( $post->ID )) {
echo ''.get_the_post_thumbnail($post->ID, 'full', array('title' => '')).'';
} ?>
<h2 class="title"><?php the_title(); ?></h2>
<?php if(get_the_excerpt()) the_excerpt(); ?>
<hr/>
</article><!--/search-result-->
<?php } ?>
<?php endwhile;
else: echo "<p>" . __('No results found', 'noo') . "</p>"; endif;?>
</div><!--/search-results-->
<?php noo_pagination(); ?>
</div> <!-- /.main -->
<?php get_sidebar(); ?>
</div><!--/.row-->
</div><!--/.container-boxed-->
</div><!--/.container-wrap-->
<?php get_footer(); ?>
<?php endif; ?>
Am I looking wrong php file? Or true
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
i have seen the previous post on the argument, but i haven't find a solution. I have this error "Parse error: syntax error, unexpected end of file" in the code, but i can't understand why. Here the code:
<?php get_header(); ?>
<?php global $thr_sidebar_opts; ?>
<?php if ( $thr_sidebar_opts['use_sidebar'] == 'left' ) { get_sidebar(); } ?>
<div class="main_content_wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<div class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
<?php if( thr_get_option('page_show_fimg') && has_post_thumbnail() ): ?>
<div class="entry-image">
<?php $img_size = $thr_sidebar_opts['use_sidebar'] ? 'thr-layout-a' : 'thr-layout-a-nosid'; ?>
<?php the_post_thumbnail($img_size); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(); ?>
</div>
<div class="clear"></div>
</article><!-- #post -->
<?php if( thr_get_option('page_show_comments') ) : ?>
<?php comments_template( '', true ); ?>
<?php endif; ?>
<?php if ( $thr_sidebar_opts['use_sidebar'] == 'right' ) { get_sidebar(); } ?>
</section>
<?php get_footer(); ?>
You have not closed the while loop. You need to add before you get th sidebar as below:
<?php get_header(); ?>
<?php global $thr_sidebar_opts; ?>
<?php if ( $thr_sidebar_opts['use_sidebar'] == 'left' ) { get_sidebar(); } ?>
<div class="main_content_wrapper">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<div class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</div>
<?php if( thr_get_option('page_show_fimg') && has_post_thumbnail() ): ?>
<div class="entry-image">
<?php $img_size = $thr_sidebar_opts['use_sidebar'] ? 'thr-layout-a' : 'thr-layout-a-nosid'; ?>
<?php the_post_thumbnail($img_size); ?>
</div>
<?php endif; ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(); ?>
</div>
<div class="clear"></div>
</article><!-- #post -->
<?php if( thr_get_option('page_show_comments') ) : ?>
<?php comments_template( '', true ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php if ( $thr_sidebar_opts['use_sidebar'] == 'right' ) { get_sidebar(); } ?>
</section>
<?php get_footer(); ?>
I set up a site for a photographer & she wanted to use her blog categories as her portfolio, which works fine, except for the fact that the infinite scrolling feature I'm using won't load all of the content for the excerpts.
The two items that it omits are the post thumbnail (image) and the horizontal row serving as a separator between the posts.
Any insight on this is appreciated - I'm using Paul Irish's infinite scroll plugin & the category excerpts are being called like so:
<?php get_header(); ?>
<section id="content" role="main">
<header class="header">
<h1 class="entry-title"><!-- <?php _e( 'Category Archives: ', 'themename' ); ?> --> <?php single_cat_title(); ?></h1>
<?php if ( '' != category_description() ) echo apply_filters( 'archive_meta', '<div class="archive-meta">' . category_description() . '</div>' ); ?>
</header>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?><div class="cat-thumbs align-right"><?php the_post_thumbnail(); ?></div>
<?php get_template_part( 'entry' ); ?>
<hr />
<?php endwhile; endif; ?>
<?php get_template_part( 'nav', 'below' ); ?>
</section>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This is the entry template:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<?php if ( is_singular() ) { echo '<h1 class="entry-title">'; } else { echo '<h2 class="entry-title">'; } ?><?php the_title(); ?><?php if ( is_singular() ) { echo '</h1>'; } else { echo '</h2>'; } ?><?php edit_post_link(); ?>
<?php if ( !is_search() ) get_template_part( 'entry', 'meta' ); ?>
</header>
<?php get_template_part( 'entry', ( is_archive() || is_search() ? 'summary' : 'content' ) ); ?>
<?php if ( !is_search() ) get_template_part( 'entry-footer' ); ?>
</article>
For reference, this is how I'm calling the excerpts for the blog, which have no issue:
<section class="entry-content">
<div class="cat-thumbs align-right"><?php the_post_thumbnail(); ?></div>
<?php the_excerpt(); ?>
<em><p>
<?php comments_number( '0 comments', '1 comment', '% comments' ); ?>.
</p></em>
<div class="entry-links"><?php wp_link_pages(); ?></div>
</section>
<hr />
Link to example
Move <div class="cat-thumbs align-right"><?php the_post_thumbnail(); ?></div> and <hr> into the entry template.
after adding the function of pagination to Functions.php and recall it in template-product-listing.php
there is nothing shown in result.
I have a big problom with this...
could you find and resolve the problem?
thnx
<article class="row">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="single-head" class="sixteen columns">
<h1><?php the_title(); ?></h1>
<?php if (has_excerpt()) { the_excerpt(); } ?>
</div>
<div class="row">
<nav id="portfolio-filters" class="sixteen columns">
<?php _e('Show All', 'ci_theme'); ?>
<?php
$args = array(
'hide_empty' => 0
);
$skills = get_terms('product-category', $args);
?>
<?php foreach ( $skills as $skill ) : ?>
<?php echo $skill->name; ?>
<?php endforeach; ?>
</nav><!-- /portfolio-filters -->
</div>
<div id="portfolio-items" class="row">
<?php $ci_product_query = new WP_Query('post_type=product&posts_per_page=4'); ?>
<?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>
<?php $item_skills = wp_get_object_terms($post->ID, 'product-category'); ?>
<article class="<?php ci_e_setting('product_columns'); ?> columns <?php foreach ( $item_skills as $item_skill ) : echo $item_skill->slug.' '; endforeach; ?> columns portfolio-item">
<a href="<?php echo get_permalink(); ?>" title="<?php echo esc_attr(get_the_title()); ?>" class="fb">
<?php the_post_thumbnail('ci_portfolio_slider', array('class'=>'scale-with-grid')); ?>
</a>
<div class="portfolio-desc">
<h3><?php the_title(); ?></h3>
<p class="desc"><?php echo mb_substr(get_the_excerpt(), 0, 70); ?>...</p>
</div>
</article><!-- /portfolio-item -->
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- /portfolio-items -->
<?php get_template_part('part', 'call_to_action'); ?>
<?php endwhile; endif; ?>
<div class="pagination">
<?php wp_pagination(); ?>
</div>
</article>
if your sure there is a post_type called products and there is posts in it...
try:
<div id="portfolio-items" class="row">
<?php $ci_product_query = new WP_Query(array('post_type'=>'product', 'posts_per_page'=> 4); ?>
<?php if ( $ci_product_query-> have_posts() ) : while ( $ci_product_query->have_posts() ) : $ci_product_query->the_post(); ?>
You know you are starting a new wp_query for every post in have_posts() ? you might want to rethink what you are trying to achieve!