We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31186
    • 20 Posts
    I had someone (who is no longer available) build me a custom listing application (e.g. craigslist) that is part of my Modx.

    What I need to do is to create a unique title tag for each listing. This was my thought, but it doesnt work:

    * put a template variable in my template: [*UniqueTitleTag*]
    * on the "listings" document, in that TV field, enter in a snippet call: [[UniqueTitleTag]]
    * in the snippet: UniqueTitleTag, I have the following:

    <?php
    For Sale: <?=$vars["make"] ?> <?=$vars["model"] ?>, <?=$vars["city"] ?>, <?=$vars["state"] ?>
    ?>
    



    P.S. The "listings" document is just calling a snippet, and the snippet itself makes several calls to a database (see below):
    <?php
    // [[EBListing]]
    
    $adminuser = 4;
    
    @ $mysession = mysql_connect("db1.mydatabase.com","mysite_modx","mypassword");
    mysql_select_db("mysite_listings");
    
    $qresult = mysql_query("SELECT * FROM listings WHERE id='".$_GET["listingid"]."' AND live='1'");
    $vars = mysql_fetch_array($qresult);
    
    //$userresult = mysql_query("SELECT * FROM modx_web_users WHERE id='$vars[user]'");
    //$uservars = mysql_fetch_array($userresult);
    
    $newviews = $vars["views"] + 1;
    $vresult = mysql_query("UPDATE listings SET views='$newviews' WHERE id='$_GET[listingid]'");
    
    $numresults = mysql_num_rows($qresult);
    if($numresults <= 0) {
    	?>
    	<h3 class="page_title">Error</h3>
    	<div id="padded">
    	<center>Listing not available</center>
    	</div>
    	<?
    } else {
    
    ?>
    <script language="JavaScript"><!--
    function openNewWin(Site)
        {NewWindow1=window.open(Site, "viewwin","toolbar=0,width=600,height=650,resizable=yes");
    	 NewWindow1.focus();}
    --></script>
    <h3 class="page_title">For Sale: <?=$vars["make"] ?> <?=$vars["model"] ?>, <?=$vars["city"] ?>, <?=$vars["state"] ?></h3>
    <div id="padded">
    <?
    if($modx->getLoginUserID() == $adminuser) {
    	?>
    	<a href="edit.html?listingid=<?=$vars["id"] ?>">Admin: Edit This Listing</a><br />
    	<?
    }
    ?>
    <table>
    <tr>
    	<td align="center" valign="top">
    	<a href="JavaScript:openNewWin('/mysite-images.php?listingid=<?=$vars["id"] ?>&start=1')"><img src="/images/mysite/<?=$vars["image1"] ?>-m.jpg" name="mainimage" style="border-style:solid;border-width:6px;border-color:#333333;margin:4px;"></a><br />
    	<?
    	$i = 2;
    	$j = 1;
    	while($i <= 20) {
    		$imagename = "image".$i;
    
    		if($vars[$imagename] != "") {
    			?><a href="JavaScript:openNewWin('/mysite-images.php?listingid=<?=$vars["id"] ?>&start=<?=$i ?>')"><img src="/images/mysites/<?=$vars[$imagename] ?>-t.jpg"  style="border-style:solid;border-width:2px;border-color:#333333;margin:1px;"></a><?
    		}
    		if($j == 3 && $vars[$imagename] != "") {
    			echo "<br />";
    			$j = 0;
    		}
    		$i++;
    		$j++;
    	}
    	?>
    	</td>
    	<td>
    	 <br />
    	</td>
    	<td valign="top">
      <h2>
    <?php
      if($vars['featured']) {
      echo '<img src="/images/featured.gif" align="absmiddle" /> ';
    }
    
    ?>
    	<?=$vars["make"] ?> <?=$vars["model"] ?></h2>
    	<?
    	$ai = $modx->getWebUserInfo($vars["user"]);
    	?>
    	<h4><strong>Seller's User Name:</strong> <?=$ai["username"] ?></h4>
    	<h4><strong>Listing Views:</strong> <?=$newviews ?></h4>
    	<h4><strong>Condition:</strong> <?=strtoupper($vars["new"]) ?></h4>
    	<h4><strong>Type:</strong> <?=strtoupper($vars["type"]) ?></h4>
    	<h4><strong>Price:</strong> $ <?=$vars["price"] ?></h4>
    	<h4>Year: <?=$vars["year"] ?></h4>
    	<h4>Length: <?=$vars["length"] ?></h4>
    	<h4>Location: <?=$vars["city"] ?>, <?=$vars["state"] ?><?=$vars["zip"] ?></h4>
    	<a href="/wish-list.html?addlisting=<?=$vars["id"] ?>"><img src="/images/wishlist.gif" border="0"></a>   <a href="/message.html?listingid=<?=$vars["id"] ?>&ebuserid=<?=$vars["user"] ?>"><img src="/images/sendmessage.gif" border="0"></a><br />
           <a href="/mail_a_friend.html?listingid=<?=$vars["id"] ?>"><img src="/images/emailafriend.gif" border="0"></a>   <a href="/printable.html?listingid=<?=$vars["id"] ?>"><img src="/images/printable.gif" border="0"></a>
    	<h4>Description:</h4>
    	<?=stripslashes($vars["description"]) ?><br />
    	<h4></h4>
    	</td>
    </tr>
    </table>
    </div>
    <?
    }
    ?>
    ?>