【问题标题】:Wordpress single page - split images & text into columnsWordpress 单页 - 将图像和文本拆分为列
【发布时间】:2011-08-16 14:10:36
【问题描述】:

我佩服thiswordpress单页(post, permalink),里面的内容分为两栏,左边是图片,右边是文字和cmets。有谁知道我如何在 wordpress 主题中复制它?怎么发这样的帖子?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果您可以编辑主题,请在列之间添加一个魔术词,例如“#NEW_COLUMN#”,然后在模板文件中打印帖子之前,拆分列

    $columns = explode("#NEW_COLUMN#", $content);
    if(count($columns) == 1)
    {
       /* print a single column page */
       echo $content;
    }
    else if(count($columns) == 2)
    {
       /* print a two column page */
       echo "<div class='left_column'>";
       echo $columns[0];
       echo "</div>";
       echo "<div class='right_column'>";
       echo $columns[1];
       echo "</div>";
    }
    else
    {
       /* ops we can't handle this many columns */
       echo $content;
    }
    

    添加然后你需要一些 css 使列最终彼此并排

    【讨论】:

    • 如果你的主题使用:the_content();它可以替换为 $content = get_the_content();
    【解决方案2】:
    add_shortcode('divider', 'shortcode_divider');
    
    function shortcode_divider(){
      return '</div><div class="column">';
    }
    

    您现在需要做的就是在帖子中添加[divider]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多