ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using a php variable in the exp:weblog:entries tag

July 13, 2009 2:00pm

Subscribe [2]
  • #1 / Jul 13, 2009 2:00pm

    newvibes

    28 posts

    Can I do this?

    {exp:weblog:entries weblog=$weblog['title']}

    I just get errors.

  • #2 / Jul 13, 2009 2:06pm

    Ingmar

    29245 posts

    No, you can’t do this. What are you trying to achieve?

  • #3 / Jul 13, 2009 2:07pm

    newvibes

    28 posts

    I’m trying to build a hierarchical page navigation, I’ve been trying for the past 8 hours to do something that takes 2 lines of code in Wordpress. Starting to get slightly frustrated :(

    The really annoying thing is I can see the admin side doing it perfectly when you view the Pages module.

  • #4 / Jul 13, 2009 2:14pm

    ender

    1644 posts

    you’ll probably have better luck leaving template tags out of the equation completely… just use php and $DB queries

  • #5 / Jul 13, 2009 2:15pm

    Ingmar

    29245 posts

    Well, you can use PHP, just need to enable it and declare it properly. Try this on “Input”:

    {exp:weblog:entries weblog="<?php echo $weblog['title'];?>"}

    Make sense? You probably need to declare the weblog array somewhere, too.

  • #6 / Jul 13, 2009 2:16pm

    newvibes

    28 posts

    Well, you can use PHP, just need to enable it and declare it properly. Try this on “Input”:

    {exp:weblog:entries weblog="<?php echo $weblog['title'];?>"}

    Make sense? You probably need to declare the weblog array somewhere, too.

    This won’t work with my template as I have php generating the XML template everything is wrapped in php already, hence why I just want to use the variable.

    What’s the point in allowing php in templates if you’re actually restricted in where you can use the php?

    <?xml version="1.0" encoding="UTF-8"?>
    <sections>
    <?php
    global $DB;
    $query = $DB->query("SELECT site_pages FROM exp_sites WHERE site_id='1'");
    if ($query->num_rows > 0) {
        foreach($query->result as $row) {
            $pages = unserialize($row['site_pages']);
            $uris = $pages['uris'];
            asort($uris);
            foreach ($uris as $uri) {
                echo "<item>";
                echo "".$uri."</permalink>";
                $segments = explode("/", $uri, -1);
                $numSegments = sizeof($segments) - 1;
                $weblogQuery = $DB->query("SELECT * FROM exp_weblog_titles WHERE url_title = '$segments[$numSegments]'");
                if ($weblogQuery->num_rows > 0){
                    foreach($weblogQuery->result as $weblog) {
                        echo "<title>".$weblog['title']."</title>";
                    }
                }
                echo "</item>";
            }
        }
    }
    ?>
    </sections>
    </sections>
  • #7 / Jul 13, 2009 2:18pm

    Ingmar

    29245 posts

    This won’t work with my template as I have php generating the XML template everything is wrapped in php already, hence why I just want to use the variable.

    Well, you’d still need an actual “echo” statement, wouldn’t you?

  • #8 / Jul 13, 2009 2:21pm

    newvibes

    28 posts

    No. If I put an echo statement there it won’t work. I just get php errors.

  • #9 / Jul 13, 2009 3:49pm

    newvibes

    28 posts

    I’ll figure something out and when I do I’ll post it here.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases