php else not working
-
Hi all,
`<?php
if ( is_singular( ‘team’ ) ) {
// Team stuff
echo ‘<h2>Team custom post type!</h2>’;
include dynamic_sidebar( ‘sidebar-4’ );if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo ‘<div class=”widget”>’;
echo ‘<h2 class=”widget-title”>Laatste nieuws van ‘ . CFS()->get( ‘team’ ) . ‘</h2>’;
echo ‘<ul class=”team-news team-news-‘ . CFS()->get( ‘team’ ) . ‘”>’;
// Use “Custom Field Suite” plugin to retrieve team name.
$args = array( ‘numberposts’ => ’10’, ‘category_name’ => CFS()->get( ‘team’ ) );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo ‘<li><a href=”‘ . get_permalink($recent[“ID”]) . ‘”>’ . $recent[“post_title”].'</a> </li> ‘;
};
echo ‘</ul>’;
echo ‘</div>’;
endwhile;
else :
echo ‘Sorry, no posts were found’;
endif;
}
else{
// Standaard stuff
echo ‘<h2>Standard post type!</h2>’;
include dynamic_sidebar( ‘sidebar-1’ );
}
?>`I’m working on a new website for a locale football club. I’m not a PHP wizard (you probably noticed), but I do somewhat understand what should happen.
So I’ve spend some time and made this piece of code on my one. I’m quite happy with the result so far, but I’m stuck now. So I could use some help.1. Not working is the “echo ‘Sorry, no posts were found’;” if there are no post (Team B2 has no post)
2. The most is working but is this correct php? Maybe is needs a cleanup?Thanks for the help.
Greetings Tom.Theme:
– Twenty Sixteen (child theme)
Plugins:
– Custom Post Type UI (to create the “Team” CPT)
– Custom Field Suite (to get the team name)
URL:
– https://www.tuna.nl/wordpress/team/a1/ (test setup for Team stuff)
– https://www.tuna.nl/wordpress/club/ (test setup for Standaard stuff)
- The topic ‘php else not working’ is closed to new replies.