Я работаю над сайтом Wordpress, который я не создавал. Разработчик использует страницу content-single.php для других частей контента на сайте. Теперь клиенту нужен блог, но я не могу использовать контент-один php.If/Else statement на одной странице блога в Wordpress
К сожалению, Wordpress ссылается на контент-single.php для отдельных страниц в блоге, но для этого нужен другой формат. Могу ли я использовать оператор if/else? Я не разработчик PHP, но я пытаюсь это исправить:
<?php if (is_category('7')) {
?>
<p>Thanks so much for your help!</p>
<?php } else { ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="container">
<?php if (get_the_post_thumbnail($post_id, 'full')) { ?>
<div class="row">
<div class="col-sm-4 col-xs-12 landing-col">
<?php echo get_the_post_thumbnail($post_id, 'full'); ?>
</div>
<div class="col-sm-8 col-xs-12">
<?php } ?>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php superhero_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="page-links">' . __('Pages:', 'superhero'), 'after' => '</div>')); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list(__(', ', 'superhero'));
/* translators: used between list items, there is a space after the comma */
$tag_list = get_the_tag_list('', __(', ', 'superhero'));
if (! superhero_categorized_blog()) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ('' != $tag_list) {
$meta_text = __('This entry was tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'superhero');
} else {
$meta_text = __('Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'superhero');
}
} else {
// But this blog has loads of categories so we should probably display them here
if ('' != $tag_list) {
$meta_text = __('This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'superhero');
} else {
$meta_text = __('This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'superhero');
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink(),
the_title_attribute('echo=0')
);
?>
<?php edit_post_link(__('Edit', 'superhero'), '<span class="edit-link">', '</span>'); ?>
</footer><!-- .entry-meta -->
<?php if (get_the_post_thumbnail($post_id, 'full')) { // if there is a first featured image & the featured image is not set to hidden, close the Bootsrap columns ?>
</div><!-- /.col -->
</div><!-- /.row -->
<?php } ?>
</div><!-- /.container -->
</article><!-- #post-## -->
<?php } ?>
Технически, категория 7 (блог) должен быть «Большое спасибо за вашу помощь» в то время как остальная часть вывода страниц оригинала кода. Но этого не происходит. Категория 7 по-прежнему выводит старый код.
Я ценю любую помощь по этому поводу, серьезно.
Касс
спасибо! пересмотрено с исправлением выше. Все еще не работает. – Cassandra
Ваш новый код создает совершенно другой вопрос. Я уверен, что вы ищете: 'if (get_the_category() == 7) {' – rnevius
Пробовал это, все еще не работая ... категория 7 все еще показывает тот же код. – Cassandra