Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
correctly written code?
#1
this code not works, but since I know nothing about php, I'm not sure that it is correct
Code:
            <?php if ( return_page_slug() == 'index' ) {
                echo '    
                        <div class="col-12 text-center">
                            <h1 itemprop="headline">'.get_page_title().'</h1>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-12">
                            <article itemscope itemtype="http://schema.org/ScholarlyArticle">
                                <div itemprop="articleBody">
                                    '.get_page_content().'
                                </div>
                            </article>
                        </div>';
                } else {
                echo '    <div class="col-8">
                            <article itemscope itemtype="http://schema.org/ScholarlyArticle">
                                <div itemprop="articleBody">
                                    '.get_page_content().'
                                </div>
                            </article>
                        </div>
                        <div class="col-4">
                            <aside id="sidebar">
                            '.get_i18n_component('sidebar').'
                            </aside>
                        </div>';
                }
            ?>
Reply
#2
(2014-03-02, 09:30:04)Oleg06 Wrote: this code not works, but since I know nothing about php, I'm not sure that it is correct
Code:
            <?php if ( return_page_slug() == 'index' ) {
                echo '    
                        <div class="col-12 text-center">
                            <h1 itemprop="headline">'.get_page_title().'</h1>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-12">
                            <article itemscope itemtype="http://schema.org/ScholarlyArticle">
                                <div itemprop="articleBody">
                                    '.get_page_content().'
                                </div>
                            </article>
                        </div>';
                } else {
                echo '    <div class="col-8">
                            <article itemscope itemtype="http://schema.org/ScholarlyArticle">
                                <div itemprop="articleBody">
                                    '.get_page_content().'
                                </div>
                            </article>
                        </div>
                        <div class="col-4">
                            <aside id="sidebar">
                            '.get_i18n_component('sidebar').'
                            </aside>
                        </div>';
                }
            ?>

What does not work?
It looks fine, but probably there is a small error somewhere. Try beginning small, with just a <div> and then add lines until it does not work anymore to find the error.

But it's more readable to do the code like this:
Code:
<?php if ( return_page_slug() == 'index' ) { ?>
  <div ... ><?php get_page_content(); ?><...
<?php } else { ?>
  ...
<?php } ?>
As the problem can only be in the PHP code, this is easier to check, as there are less PHP code lines.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#3
Oleg,

At first glance I think that you should use get_page_title(false), get_page_content(false) and return_i18n_component('sidebar') in your current code.

But that wouldn't be necessary if you do it the way mvlcek suggests, I also think it's better to do it that way.
Reply
#4
many thanks
Code:
        <!-- main -->
        <section class="container main">
            <?php if ( return_page_slug() == 'index' ) { ?>
            <div class="col-12 text-center">
                <h1 itemprop="headline"><?php get_page_title(); ?></h1>
            </div>
            <div class="clearfix"></div>
            <?php } ?>
            <div class="<?php if ( return_page_slug() == 'index' ) {echo "12";} else {echo "8";} ?>">
                <article itemscope itemtype="http://schema.org/ScholarlyArticle">
                    <div itemprop="articleBody">
                        <?php get_page_content(); ?>
                    </div>
                </article>
            </div>
                <?php if (return_page_slug()!='index') get_i18n_component('sidebar'); ?>
            <div class="clearfix"></div>
        </section>
        <!-- /main -->
Reply




Users browsing this thread: 1 Guest(s)