dongwai4434 2012-05-04 13:21 采纳率: 0%
浏览 15
已采纳

PHP语法和逻辑中的PHP

I'm using the following which is working:

<?php if ( is_singular() ) {} else {echo '<h1>';} ?><a href="<?php echo home_url() ?>/" title="<?php bloginfo( 'name' ) ?>" rel="home"><?php bloginfo( 'name' ) ?></a><?php if ( is_singular() ) {} else {echo '</h1>';} ?>

It sets the site title as h1 and post titles to h2, unless on an individual post page, it removes the site title h1 and makes the post title an h1 header for SEO purposes.

I've added an options page to my WordPress theme which is also working for straight forward settings. Where I run into trouble is PHP inside PHP because now I want to make this a little more advanced and add a custom logo option. So if I add:

<?php $options = get_option('kittens_options'); echo $options['logo']; ?>

and connect that to the options page I can set a logo. What I want to do however, is combine these two codes into one big conditional:

<?php $options = get_option('kittens_options'); echo $options['logo'];
else {
if ( is_singular() ) {} else {echo '<h1>';}<a href="echo home_url()/" title="bloginfo( 'name' )" rel="home">bloginfo( 'name' )</a>if ( is_singular() ) {} else {echo '</h1>';}
} ?>
  • 写回答

2条回答 默认 最新

  • dougu2006 2012-05-04 13:31
    关注

    Try this.

        <?php 
    $options = get_option('kittens_options');
    if (!is_singular() ) {echo '<h1>';}
    echo '<a href="'.home_url().'" title="'.bloginfo( 'name' ).'" rel="home">';
        if($options['logo']!="")
            echo $options['logo'];
        else
            echo bloginfo( 'name' );
    echo '</a>';
    if (!is_singular() ) {echo '</h1>';}
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度