最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How do I add a predefined class to a custom html element?

programmeradmin2浏览0评论

I have a basic loop within single.php Also the class .title_name within style.css hooked up with functions.php i.e all is set and working. My code snippet below:

<?php
                    while(have_posts()) {
                        the_post();
                    ?> 
                    <!-- HTML STARTS HERE -->
                    <h2 <?php echo $titleTemplate; ?> ><?php the_title(); ?></h2>
                    <!-- HTML ENDS UP HERE -->
                    <p><?php the_content(); ?></p>
                    <?php } ?>
                    <?php 
                    if (is_single()) : return $titleTemplate = 'class="title_name"';
                    endif; ?>

As far as I am considered I have to write simple IF statement which checks if I am within any post, if true It should return a variable with some class assigned to. After I just do echo within desirable opening tag elment but no result at all. Maybe it's scope issue. I am not very familiar with wordpress coding nor php itself yet so any help would be appreciated.

发布评论

评论列表(0)

  1. 暂无评论