Display child terms if there are posts on custom taxonomy template - wordpress

I have a piece of code that shows child terms of a custom taxonomy of the current parent term in the taxonomy-term.php template file. I want to display html only when there are child terms present. Now the heading 2 is displayed even when there are no child terms. Here is the code:
<?php
$term_children = get_terms('onderwerp', array( 'parent' => get_queried_object_id(),));
if ( ! is_wp_error( $terms ) || ($term_children->count != 0) ) { ?>
<section>
<h2>Ik heb een vraag over:</h2>
<div class="onderwerp-links">
<?php
foreach ( $term_children as $child ) { ?>
<?php $img = get_term_meta( $term->term_id, 'ndftm_img', true ); ?>
<a href="<?php echo esc_url( get_term_link( $child ) ) ?>" style="background-image: url(<?php echo $img; ?>)">
<span><?php echo $child->name; ?></span>
</a><?php
}
?>
</div>
</section>
<?php
}
?>

I fixed it by adding
'hide_empty' => true
in the get terms array
and making the if statement like this:
if ( ! empty($term_children) )
Here's the code:
<?php
$term_children = get_terms('onderwerp', array( 'parent' => get_queried_object_id(), 'hide_empty' => true ));
if ( ! empty($term_children) ) { ?>
<section>
<h2>Ik heb een vraag over:</h2>
<div class="onderwerp-links">
<?php
foreach ( $term_children as $child ) { ?>
<?php $img = get_term_meta( $term->term_id, 'ndftm_img', true ); ?>
<a href="<?php echo esc_url( get_term_link( $child ) ) ?>" style="background-image: url(<?php echo $img; ?>)">
<span><?php echo $child->name; ?></span>
</a><?php
}
?>
</div>
</section>
<?php
}
?>

Related

Critical Error on wordpress php code when listing custom posts from a category

Recently having problems probably because of a wordpress update. This was working and now it isn't. I am using advanced custom fields to grab the category id. Any one know what is going on here?
<?php
$args = array(
'post_type' => 'messages_single',
'posts_per_page' => 10,
'cat' => '' . get_field('category') . '',
'order' => ASC,
);
$q = new WP_Query( $args);
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post(); ?>
<div class="series-item">
<div class="series-thumb">
<?php if ( has_post_thumbnail() ) { ?>
<img src="<?php the_post_thumbnail_url( 'full' ); ?>" alt="<?php the_title(); ?>" class="zoom" /></div>
<?php
}
else { ?>
<img src="/img/image-holder.png" alt="<?php the_title(); ?>" /></div>
<?php } ?>
<div class="series-info">
<h3><?php the_title(); ?></h3>
<div class="mspeaker">
<?php
if(get_field('other_speaker'))
{
echo '' . get_field('other_speaker') . '';
}
else {
echo '' . get_field('speaker') . '';
}
?>
</div>
</div><!-- .series-item-->
<?php }
wp_reset_postdata();
}
?>

Change header template from Divi theme

I have this template(header.php). Now i'm working on a site, and i want to to some changes in this template. According to this template i get 2 menu locations, but i want to change the order of them.
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<?php
elegant_description();
elegant_keywords();
elegant_canonical();
/**
* Fires in the head, before {#see wp_head()} is called. This action can be used to
* insert elements into the beginning of the head before any styles or scripts.
*
* #since 1.0
*/
do_action( 'et_head_meta' );
$template_directory_uri = get_template_directory_uri();
?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<script type="text/javascript">
document.documentElement.className = 'js';
</script>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php
$product_tour_enabled = et_builder_is_product_tour_enabled();
$page_container_style = $product_tour_enabled ? ' style="padding-top: 0px;"' : ''; ?>
<div id="page-container"<?php echo et_core_intentionally_unescaped( $page_container_style, 'fixed_string' ); ?>>
<?php
if ( $product_tour_enabled || is_page_template( 'page-template-blank.php' ) ) {
return;
}
$et_secondary_nav_items = et_divi_get_top_nav_items();
$et_phone_number = $et_secondary_nav_items->phone_number;
$et_email = $et_secondary_nav_items->email;
$et_contact_info_defined = $et_secondary_nav_items->contact_info_defined;
$show_header_social_icons = $et_secondary_nav_items->show_header_social_icons;
$et_secondary_nav = $et_secondary_nav_items->secondary_nav;
$et_top_info_defined = $et_secondary_nav_items->top_info_defined;
$et_slide_header = 'slide' === et_get_option( 'header_style', 'left' ) || 'fullscreen' === et_get_option( 'header_style', 'left' ) ? true : false;
?>
<?php if ( $et_top_info_defined && ! $et_slide_header || is_customize_preview() ) : ?>
<?php ob_start(); ?>
<div id="top-header"<?php echo $et_top_info_defined ? '' : 'style="display: none;"'; ?>>
<div class="container clearfix">
<?php if ( $et_contact_info_defined ) : ?>
<div id="et-info">
<?php if ( '' !== ( $et_phone_number = et_get_option( 'phone_number' ) ) ) : ?>
<span id="et-info-phone"><?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?></span>
<?php endif; ?>
<?php if ( '' !== ( $et_email = et_get_option( 'header_email' ) ) ) : ?>
<span id="et-info-email"><?php echo esc_html( $et_email ); ?></span>
<?php endif; ?>
<?php
if ( true === $show_header_social_icons ) {
get_template_part( 'includes/social_icons', 'header' );
} ?>
</div> <!-- #et-info -->
<?php endif; // true === $et_contact_info_defined ?>
<div id="et-secondary-menu">
<?php
if ( ! $et_contact_info_defined && true === $show_header_social_icons ) {
get_template_part( 'includes/social_icons', 'header' );
} else if ( $et_contact_info_defined && true === $show_header_social_icons ) {
ob_start();
get_template_part( 'includes/social_icons', 'header' );
$duplicate_social_icons = ob_get_contents();
ob_end_clean();
printf(
'<div class="et_duplicate_social_icons">
%1$s
</div>',
et_core_esc_previously( $duplicate_social_icons )
);
}
if ( '' !== $et_secondary_nav ) {
echo et_core_esc_wp( $et_secondary_nav );
}
et_show_cart_total();
?>
</div> <!-- #et-secondary-menu -->
</div> <!-- .container -->
</div> <!-- #top-header -->
<?php
$top_header = ob_get_clean();
/**
* Filters the HTML output for the top header.
*
* #since 3.10
*
* #param string $top_header
*/
echo et_core_intentionally_unescaped( apply_filters( 'et_html_top_header', $top_header ), 'html' );
?>
<?php endif; // true ==== $et_top_info_defined ?>
<?php if ( $et_slide_header || is_customize_preview() ) : ?>
<?php ob_start(); ?>
<div class="et_slide_in_menu_container">
<?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) || is_customize_preview() ) { ?>
<span class="mobile_menu_bar et_toggle_fullscreen_menu"></span>
<?php } ?>
<?php
if ( $et_contact_info_defined || true === $show_header_social_icons || false !== et_get_option( 'show_search_icon', true ) || class_exists( 'woocommerce' ) || is_customize_preview() ) { ?>
<div class="et_slide_menu_top">
<?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) ) { ?>
<div class="et_pb_top_menu_inner">
<?php } ?>
<?php }
if ( true === $show_header_social_icons ) {
get_template_part( 'includes/social_icons', 'header' );
}
et_show_cart_total();
?>
<?php if ( false !== et_get_option( 'show_search_icon', true ) || is_customize_preview() ) : ?>
<?php if ( 'fullscreen' !== et_get_option( 'header_style', 'left' ) ) { ?>
<div class="clear"></div>
<?php } ?>
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php
printf( '<input type="search" class="et-search-field" placeholder="%1$s" value="%2$s" name="s" title="%3$s" />',
esc_attr__( 'Search …', 'Divi' ),
get_search_query(),
esc_attr__( 'Search for:', 'Divi' )
);
?>
<button type="submit" id="searchsubmit_header"></button>
</form>
<?php endif; // true === et_get_option( 'show_search_icon', false ) ?>
<?php if ( $et_contact_info_defined ) : ?>
<div id="et-info">
<?php if ( '' !== ( $et_phone_number = et_get_option( 'phone_number' ) ) ) : ?>
<span id="et-info-phone"><?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?></span>
<?php endif; ?>
<?php if ( '' !== ( $et_email = et_get_option( 'header_email' ) ) ) : ?>
<span id="et-info-email"><?php echo esc_html( $et_email ); ?></span>
<?php endif; ?>
</div> <!-- #et-info -->
<?php endif; // true === $et_contact_info_defined ?>
<?php if ( $et_contact_info_defined || true === $show_header_social_icons || false !== et_get_option( 'show_search_icon', true ) || class_exists( 'woocommerce' ) || is_customize_preview() ) { ?>
<?php if ( 'fullscreen' === et_get_option( 'header_style', 'left' ) ) { ?>
</div> <!-- .et_pb_top_menu_inner -->
<?php } ?>
</div> <!-- .et_slide_menu_top -->
<?php } ?>
<div class="et_pb_fullscreen_nav_container">
<?php
$slide_nav = '';
$slide_menu_class = 'et_mobile_menu';
$slide_nav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) );
$slide_nav .= wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'container' => '', 'fallback_cb' => '', 'echo' => false, 'items_wrap' => '%3$s' ) );
?>
<ul id="mobile_menu_slide" class="<?php echo esc_attr( $slide_menu_class ); ?>">
<?php
if ( '' === $slide_nav ) :
?>
<?php if ( 'on' === et_get_option( 'divi_home_link' ) ) { ?>
<li <?php if ( is_home() ) echo( 'class="current_page_item"' ); ?>><?php esc_html_e( 'Home', 'Divi' ); ?></li>
<?php }; ?>
<?php show_page_menu( $slide_menu_class, false, false ); ?>
<?php show_categories_menu( $slide_menu_class, false ); ?>
<?php
else :
echo et_core_esc_wp( $slide_nav ) ;
endif;
?>
</ul>
</div>
</div>
<?php
$slide_header = ob_get_clean();
/**
* Filters the HTML output for the slide header.
*
* #since 3.10
*
* #param string $top_header
*/
echo et_core_intentionally_unescaped( apply_filters( 'et_html_slide_header', $slide_header ), 'html' );
?>
<?php endif; // true ==== $et_slide_header ?>
<?php ob_start(); ?>
<header id="main-header" data-height-onload="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>">
<div class="container clearfix et_menu_container">
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && ! empty( $user_logo )
? $user_logo
: $template_directory_uri . '/images/logo.png';
ob_start();
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
$logo_container = ob_get_clean();
/**
* Filters the HTML output for the logo container.
*
* #since 3.10
*
* #param string $logo_container
*/
echo et_core_intentionally_unescaped( apply_filters( 'et_html_logo_container', $logo_container ), 'html' );
?>
<div id="et-top-navigation" data-height="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>" data-fixed-height="<?php echo esc_attr( et_get_option( 'minimized_menu_height', '40' ) ); ?>">
<?php if ( ! $et_slide_header || is_customize_preview() ) : ?>
<nav id="top-menu-nav">
<?php
$menuClass = 'nav';
if ( 'on' === et_get_option( 'divi_disable_toptier' ) ) $menuClass .= ' et_disable_top_tier';
$primaryNav = '';
$primaryNav = wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => 'top-menu', 'echo' => false ) );
if ( empty( $primaryNav ) ) :
?>
<ul id="top-menu" class="<?php echo esc_attr( $menuClass ); ?>">
<?php if ( 'on' === et_get_option( 'divi_home_link' ) ) { ?>
<li <?php if ( is_home() ) echo( 'class="current_page_item"' ); ?>><?php esc_html_e( 'Home', 'Divi' ); ?></li>
<?php }; ?>
<?php show_page_menu( $menuClass, false, false ); ?>
<?php show_categories_menu( $menuClass, false ); ?>
</ul>
<?php
else :
echo et_core_esc_wp( $primaryNav );
endif;
?>
</nav>
<?php endif; ?>
<?php
if ( ! $et_top_info_defined && ( ! $et_slide_header || is_customize_preview() ) ) {
et_show_cart_total( array(
'no_text' => true,
) );
}
?>
<?php if ( $et_slide_header || is_customize_preview() ) : ?>
<span class="mobile_menu_bar et_pb_header_toggle et_toggle_<?php echo esc_attr( et_get_option( 'header_style', 'left' ) ); ?>_menu"></span>
<?php endif; ?>
<?php if ( ( false !== et_get_option( 'show_search_icon', true ) && ! $et_slide_header ) || is_customize_preview() ) : ?>
<div id="et_top_search">
<span id="et_search_icon"></span>
</div>
<?php endif; // true === et_get_option( 'show_search_icon', false ) ?>
<?php
/**
* Fires at the end of the 'et-top-navigation' element, just before its closing tag.
*
* #since 1.0
*/
do_action( 'et_header_top' );
?>
</div> <!-- #et-top-navigation -->
</div> <!-- .container -->
<div class="et_search_outer">
<div class="container et_search_form_container">
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php
printf( '<input type="search" class="et-search-field" placeholder="%1$s" value="%2$s" name="s" title="%3$s" />',
esc_attr__( 'Search …', 'Divi' ),
get_search_query(),
esc_attr__( 'Search for:', 'Divi' )
);
?>
</form>
<span class="et_close_search_field"></span>
</div>
</div>
</header> <!-- #main-header -->
<?php
$main_header = ob_get_clean();
/**
* Filters the HTML output for the main header.
*
* #since 3.10
*
* #param string $main_header
*/
echo et_core_intentionally_unescaped( apply_filters( 'et_html_main_header', $main_header ), 'html' );
?>
<div id="et-main-area">
<?php
/**
* Fires after the header, before the main content is output.
*
* #since 3.10
*/
do_action( 'et_before_main_content' );
In practice the secondary menu appears first, before primary menu. How to change the ordering for displaying:
FIRST: Primary menu;
SECOND: Secondary menu;
Who knows how could i change the order, for displaying the same order that i described above?
First of all, it is not advisable to change the order of the menu in the DIVI theme. Just rearranging the code will collapse the header.
So it is better to register a new Navigation Menu and then use it where you wanted.
Before making any changes to the theme files, make sure you are using Divi Child Theme. If you don't have one, You can download it here (Divi Child Theme Download Link)
Then you can copy your header.php file from Divi theme folder and paste it into the Child theme folder.
To register a custom menu, use the below code in the Functions.php file.
function wpb_custom_new_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'wpb_custom_new_menu' );
Now go to Appearance -> Menus and create a New Menu and assign it as "My Custom Menu".
To add this menu to the header, Add the below code in header.php where you want to display the menu.
'my-custom-menu',
'container_class' => 'custom-menu-class' ) );
?>
Then you can use the .custom_menu_class CSS class to style the menu.

Displaying short product description of woocommerce product via ACF Repeater field

My code is below
It’s essentially bringing out a woocommerce product as a post object inside a repeater field.
It’s pretty much working fine with two exceptions.
It’s giving an error for using get_attribute for the $scent variable
The $description variable should pull the Product Short Description, but its not bringing anything back.
Any help would be very much appreciated!
<?php if ( have_rows( 'products' ) ) : ?>
<?php while ( have_rows( 'products' ) ) : the_row(); ?>
<?php $post_object = get_sub_field( 'product' ); ?>
<?php if ( $post_object ): ?>
<?php $post = $post_object; ?>
<?php setup_postdata( $post );
global $post;
$logoImageHtml = '';
$subCollectionHtml = '';
$imageAlt = '';
$hoverImage = '';
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'parent',
'order' => 'ASC',
'menu_order' => 'ASC',
'pad_counts' => 0,
'hierarchical' => 1,
'hide_empty' => 1
);
$terms = wc_get_product_terms(get_the_ID(), 'product_cat', $args);
if (!empty($terms) && is_array($terms)) {
$terms = array_reverse($terms);
$term = (!empty($terms[1]) ? $terms[1] : null);
if (!empty($term->name)) {
$imageAlt = $term->name;
}
$term = (!empty($terms[2]) ? $terms[2] : null);
if (!empty($term->name)) {
$subCollectionHtml = "{$term->name}
";
}
}
$scent = $post->get_attribute('scent');
$scent = (!empty($scent) ? explode(', ', $scent) : null);
$description = get_short_description ( $post->post->ID );
// $description = $post->post->post_excerpt;
$thumbImage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->post->ID ), 'shop_catalog' );
if (get_field('product_logo_image')) {
$logoImage = get_field('product_logo_image');
if (!empty($logoImage)) {
$logoImageHtml = "<h3><img class='product-logo' src='$logoImage' alt='$imageAlt'/></h3>";
}
}
if (get_field('product_grid_scent_image')) {
$hoverImage = get_field('product_grid_scent_image');
}
?>
<li class="product">
<div class="front">
<div class="image">
<?php if (!empty($thumbImage)): ?>
<img src="<?php echo $thumbImage[0]; ?>" data-id="<?php echo $post->post->ID; ?>">
<?php endif; ?>
</div>
<?php if ($logoImageHtml || $subCollectionHtml || $scent): ?>
<div class="text">
<?php echo $logoImageHtml; ?>
<?php echo $subCollectionHtml; ?>
<?php
if (!empty($scent) && is_array($scent)): ?>
<div class="scent">
<ul>
<?php foreach ($scent as $key => $value): ?>
<li><?php echo $value; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="back">
<div class="frame">
<div class="content">
<?php if (!empty($hoverImage)): ?>
<div class="image">
<img src="<?php echo $hoverImage; ?>" alt="Scent"/>
</div>
<?php endif; ?>
<div class="text">
<?php
if (!empty($description)): ?>
<?php echo $description; ?>ssss
<?php endif; ?>
View details
</div>
</div>
</div>
</div>
</li>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>

Making text appear above the static picture slider on the Alt homepage, with static slider template on Wordpress

Basically I'm making a site on Wordpress using the Wordpress theme "Restaurateur". As you can see on the demo home page here http://wprestaurateur.com/ using the Alt homepage with static slider template, below the navigation is the picture slider and then below that some text. I've basically completed the site except I want the text to show up first and then have the picture slider below it. I've tried all I can think of with no luck. Any suggestions? Thanks.
EDIT: Added the .php file for the template im using for the home page.
<div id="content" class="clearfix">
<div id="main" class="clearfix sldr" role="main">
<div id="slide-wrap">
<?php if ( have_posts() ) : ?>
<div id="load-cycle"></div>
<div class="cycle-slideshow alt-static" <?php
if ( get_theme_mod('restaurateur_slider_effect') ) {
echo 'data-cycle-fx="' . wp_kses_post( get_theme_mod('restaurateur_slider_effect') ) . '" data-cycle-tile-count="10"';
} else {
echo 'data-cycle-fx="scrollHorz"';
}
?> data-cycle-slides="> div.slides" <?php
if ( get_theme_mod('restaurateur_slider_timeout') ) {
$slider_timeout = wp_kses_post( get_theme_mod('restaurateur_slider_timeout') );
echo 'data-cycle-timeout="' . $slider_timeout . '000"';
} else {
echo 'data-cycle-timeout="3000"';
}
?> >
<div class="cycle-pager"></div>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_shortcode( $post->post_content, 'gallery' ) ) : ?>
<?php
$gallery = get_post_gallery( $post, false );
$ids = explode( ",", $gallery['ids'] );
$hasgallery = 1;
foreach( $ids as $id ) {
$title = get_post_field('post_title', $id);
$meta = get_post_field('post_excerpt', $id);
$link = wp_get_attachment_url( $id );
$image = wp_get_attachment_image( $id, array( 1000, 640 ));
?>
<div class="slides">
<div id="post-<?php the_ID(); ?>" <?php post_class('post-theme'); ?>>
<div class="slide-thumb"><?php echo $image; ?></div>
</div>
</div><!-- .slides -->
<?php } ?>
<?php else : ?>
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) { ?>
<div class="slides">
<div id="post-<?php the_ID(); ?>" <?php post_class('post-theme'); ?>>
<div class="slide-thumb"><?php echo wp_get_attachment_image( $attachment->ID, array( 1000, 640 ), false, '' ); ?></div>
</div>
</div>
<?php }
} else {
?>
<div class="no-slide-image"><?php _e('Images added to this page will appear here', 'restaurateur'); ?></div>
<?php
} ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<?php $content = restaurateur_content(9999); ?>
<?php $content = preg_replace(array('{<a[^>]*><img}','{/></a>}'), array('<img','/>'), $content); ?>
<?php $content = preg_replace('/<img[^>]+./', '', $content); ?>
<?php $content = preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content); ?>
<div class="intro-content">
<?php echo $content; ?>
</div>
</div> <!-- end #main -->
</div> <!-- end #content -->
Well we need to see the php file for your homepage to be able to help. But there will be a function that calls the slider, and you'll need to move it below the text content area. Or you can just add some text ahead of that slider function yourself.

All posts on page of one category

I really can't figure this out. I'm trying to have posts all posts on a page from one category, but I still get all categories. This is the code I'm using now. I thought I could manage with WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );, but it totally drives me nuts.
<?php /* Template Name: Blog */ ?>
<?php get_header(); ?>
<div id="content-wrap">
<div id="content">
<div class="post_content">
<h1 class="archive_title"><?php the_title(); ?></h1>
<?php
$query['post_type'] = 'post';
// WP 3.0 PAGED BUG FIX
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query['paged'] = $paged;
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) { $recipe_posts->the_post(); }
query_posts($query);
if (have_posts()) : ?>
<?php $more = 0; ?>
<div class="posts">
<?php while (have_posts()) : the_post();
$is_recipe = in_category('Resep'); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<?php if (option::get('index_thumb') == 'on') {
get_the_image( array( 'size' => 'loop', 'width' => option::get('thumb_width'), 'height' => option::get('thumb_height'), 'before' => '<div class="post-thumb">', 'after' => '</div>' ) );
} ?>
<div class="details">
<h2 class="title"><?php the_title(); ?></h2>
<?php if ( option::get('display_meta') == 'on' ) { ?>
<div class="meta">
<?php
if ( $is_recipe ) {
$fields = get_fields();
if ( !empty( $fields ) ) echo $fields;
} else { ?>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/person.png'; ?>" /><?php _e('Author', 'wpzoom'); ?>:</strong><?php the_author_posts_link(); ?></p>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/clock.png'; ?>" />
<?php _e('Posted', 'wpzoom'); ?>
:</strong> <?php echo get_the_date(); ?></p>
<?php } ?>
</div>
<?php } ?>
<div class="entry">
<?php the_content('<span>'.__('Read More', 'wpzoom').' ›</span>'); ?>
</div>
<p>
<?php if ( option::get('display_readmore') == 'on' && (option::get('display_content') == 'Excerpt') ) { ?>
<a href="<?php the_permalink(); ?>" class=" clean more-link">
<?php _e( ( $is_recipe ? 'Lihat Resep' : 'Read More' ), 'wpzoom' ); ?>
</a>
<?php } ?>
<?php edit_post_link( __('Edit', 'wpzoom'), ' <small>', '</small>' ); ?>
</p>
</div>
<div class="cleaner"> </div>
</div>
<!-- /.post -->
<?php endwhile; ?>
</div>
<div class="cleaner"> </div>
<?php get_template_part( 'pagination' ); ?>
<?php wp_reset_query(); ?>
<div class="cleaner"> </div>
<?php endif; ?>
</div><!-- / .post_content -->
</div><!-- / #content -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You're making it far too complex, just specificy the stuff you need inside the while loop:
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) {
$recipe_posts->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_query();
You have entered loop inside loop, try this following with cleaning your code:
$args = array('posts_per_page' => -1 , 'category_name' => 'resep');
$recipe_posts = new WP_Query($args);
if($recipe_posts->have_posts()) :
while($recipe_posts->have_posts()) :
$recipe_posts->the_post();
?>
<h1><?php the_title() ?></h1>
<div class='post-content'><?php the_content() ?></div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
I cleaned the whole template, but posts from other categories were still there. In the end I managed with these lines
global $wp_query;
$args = array_merge( $wp_query->query, array( 'category_name' => 'resep' ) );
query_posts( $args );
$recipe_posts = new WP_Query($args);
$more = 0;
if($recipe_posts->have_posts()) :
while ($recipe_posts->have_posts()) : $recipe_posts->the_post();?>

Resources