We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1447
    • 7 Posts
    Hi alla!

    I’m trying to include some PHP code, but no luck so far sad

    I want to place this in the header:

    <?php 
    define('WP_USE_THEMES', false);
    require('./wordpress/wp-blog-header.php');
    get_header();
    ?>


    ... so i can include my last blog post.

    <?php get_sidebar(); ?>


    ... in a blog div

    I have placed all code in a snippet and include it, but have not got i t to work.
    How do i do?

    Thanks you!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      All snippet code is evaluated by the parser much the same way as a function is evaluated by a normal php script, so it has to return its output just as a function does.

      return get_header();
      
      return get_sidebar();
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 1447
        • 7 Posts
        Thanks for the answer! smiley

        I placed this:

        <?php
        define('WP_USE_THEMES', false);
        require('./wordpress/wp-blog-header.php');
        return get_header();
        ?>


        ... in to snippet [[head]] and placed the [[head]] at the very top of my index.

        When i save and reload the index it is all blank.

        Am i missing something? huh
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Is this supposed to supply the <head>...</head> part of your HTML page? In that case, put it at the beginning of your template, not a document’s content.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 1447
            • 7 Posts
            Hi!

            No, as you can see in the PHP code:

            <?php
            define('WP_USE_THEMES', false);
            require('./wordpress/wp-blog-header.php');
            return get_header();
            ?>


            it does not write out any HTML.

            I just want to place out two snippets att my docment;

            <?php 
            define('WP_USE_THEMES', false);
            require('./wordpress/wp-blog-header.php');
            get_header();
            ?>


            And

            <?php get_sidebar(); ?>


            [[headblogg]]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <title>Title Yes :)</title>
            <base href="[(site_url)]" />
            
            
            <link rel="stylesheet" type="text/css" media="all" href="style.css" />
            </head>
            
            <body>
            <div id="latest_blogg">
             [[the other snippet (<?php get_sidebar(); ?>)]]
            </div>
            ...
            


            Hope it makes some sense! smiley
              • 1447
              • 7 Posts
              Anyone? kiss
                • 16886
                • 40 Posts
                Quote from: Ananassa at Jan 29, 2007, 04:33 AM

                [[headblogg]]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                <title>Title Yes :)</title>
                <base href="[(site_url)]" />
                
                
                <link rel="stylesheet" type="text/css" media="all" href="style.css" />
                </head>
                
                <body>
                <div id="latest_blogg">
                 [[the other snippet (<?php get_sidebar(); ?>)]]
                </div>
                ...
                


                Hi Ananassa,
                your Document is not valid! The first content of a Website MUST the DOCTYPE-Declaration, the browser don’t know what type of content has to be loaded... the [[headblogg]] part seems not to be valid because it is in front of the doctype declaration, take a look on the generated sourcecode in your browser...

                If you want to use any PHP-Code in your documents, put them into snippets and then call the snippets like : [[mysnippet]]
                If you want to use HTML-Code in your documents, put them into chunks and then call the chunks like : {{mychunk}}

                HTH
                Greetings
                LeftHanded
                  I love ModX!