DOM Properties in wordpress?

Discussion in 'iOS Programming' started by newtoiphonesdk, Sep 3, 2010.

Thread Status:
Not open for further replies.
  1. newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    I am using an nsstring and stringbyevaluatingjavascript document.title to get the title of an article on wordpress. I have used it other places and it gets the title just fine but with wordpress it returns the title of the entire blog instead of the title of the current article. Does anyone know what dom properties can be easily used with wordpress?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Seeing as Wordpress blogs can have a variety of templates, you probably can't count on a single or group of elements across all of them. But most likely there is an RSS feed associated with it which would be standardized.
     
  3. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #3
    Makes sense. I was hoping I would be able to do that with just common webviews and htmls and not have to mess with parsing xmls with using the RSS feed though.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
  5. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Can we see the code you are using to pull the document title?

    EDIT: Also, can we see the code you are using to populate the UIWebView?
     
  7. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #7
    In the .m to get the title and URL of the webview I am using this:
    Code:
    -(IBAction)showPicker:(id)sender
    {self.currentURL = blog.request.URL.absoluteString;
    	self.title = [blog stringByEvaluatingJavaScriptFromString:@"document.title"];
    	// This sample can run on devices running iPhone OS 2.0 or later  
    	// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later. 
    	// So, we must verify the existence of the above class and provide a workaround for devices running 
    	// earlier versions of the iPhone OS. 
    	// We display an email composition interface if MFMailComposeViewController exists and the device can send emails.
    	// We launch the Mail application on the device, otherwise.
    	
    	Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    	if (mailClass != nil)
    	{
    		// We must always check whether the current device is configured for sending emails
    		if ([mailClass canSendMail])
    		{
    			[self displayComposerSheet];
    		}
    		else
    		{
    			[self launchMailAppOnDevice];
    		}
    	}
    	else
    	{
    		[self launchMailAppOnDevice];
    	}
    }
    
    
    The webview code is here:
    Code:
    - (void)viewDidLoad {
         [blog loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://theipadpreacher.wordpress.com"]]];
    	
        [super viewDidLoad];
    }
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Okay, but the document.title of the @"http://theipadpreacher.wordpress.com/" webpage IS "The iPad Preacher". That's the page your webview is loading; not the individual blog entry. The document.title of the @"http://theipadpreacher.wordpress.com/2010/08/17/the-color-coded-family/" webpage, on the other hand, is "The Color Coded Family « The iPad Preacher".
     
  9. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #9
    That is the page it loads to when the app is launched. The evaluatebyjavascript part is in the ibaction code to send an email, so shouldn't it get the title of the current page? It gets the URL of the current page but not the title?

    EDIT: what I am meaning is when someone selects an article then clicks the email button, the email button is what has the document.title code in it, so it should get what the current page is?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    So, are you saying that self.currentURL is being set to @"http://theipadpreacher.wordpress.com/2010/08/17/the-color-coded-family/" but self.title is being set to @"The iPad Preacher"? You've confirmed this?

    How are they selecting an article, again?
     
  11. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #11
    They are selecting the article by pushing the title of the article in the webview, and it loads up there. Here are some screenshots I took of the app. The first is what it loads to, the second is after I click on an article, the third is the email it composes when I click the email button inside one of the article pages. As you can see in the third picture, it gets the URL of the article, but not the title.
    [​IMG]
    [​IMG]
    [​IMG]
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    I guess I would check the HTML rendered, since that seems to be different than the page rendered through a regular browser; as seen in attached screenshot (is it some iPhone-optimized version?), and look at what the <title> is being set to.
     

    Attached Files:

  13. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #13
    Yes wordpress detects mobile devices and uses the mobile theme automatically. How do I figure out what the <title> is being set to? Just in the source of the HTML?
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    Yes.
     
  15. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #15
    Ok. I'll check that out an see what all is different. On a similar note. What property gives just the article text? I tried document.innerText and document.innerHTML but it gives everything including the rss icons and ads
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    There is no specific property for the article text. This is just regular HTML, not some kind of blog-specific XML feed or even RSS feed. You may have better luck retrieving and parsing the RSS version of these pages.
     
  17. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #17
    Ok. Was afraid of that. As you can see by earlier threads I have had problems with Parsing rss
     
  18. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #18
    Which threads would those be?
     
  19. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #19
    It's been a while. Tab bar rss application or something like that in the title
     
  20. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #20
    Do you know it's fairly easy to find all the threads you've created?
     
  21. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #21
    Yea, but a lot of my posts I was doing on the iPhone, and it's a bit more of a pain to do all that in the middle of replying to a text so i stayed somewhat vague.

    I went through my wordpress blog viewing the source, and it does show the title for the individual article as showing the article name, so I'm still unsure about why it will not work. I put in a friend's blog:
    Code:
    http://preachinghelp.org
    in place of my blog, and it pulled in the article title fine, so I think it has to be something to do with wordpress, and not the code itself.

    I went through the source code as well to find out the div iD of the entry. Here is a snippet of that source:
    Code:
    <div class="entrytext">
    				<div class='snap_preview'><p>I had an interesting and fun couple of days this past weekend. 
    To get the entrytext in the body of my email, how would I string that? Would it be something like this?
    Code:
    self.title = [blog stringByEvaluatingJavaScriptFromString:@"document.getElementById(entrytext).innerText"];
    By the way, that code didn't put anything into that email, just wondering if I'm on the right track, or if that needs to be something different.
     
  22. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #22
    Well, I looked through all the titles of the threads you created and didn't find anything even close to what you mentioned.

    Make sure you are viewing the HTML source for the mobile-optimized version that Wordpress is rendering because, from what I can tell, here is the HTML of the page you are trying to extract info from:
    HTML:
    <html xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11">
    	<meta name="generator" content="WordPress MU">
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    	<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">
    	<title>The iPad Preacher</title>
    	<link rel="alternate" type="application/rss+xml" title="The iPad Preacher RSS Feed" href="http://theipadpreacher.wordpress.com/feed/">
    	<link rel="apple-touch-icon" href="http://s2.wp.com/wp-content/themes/pub/wptouch/images/icon-pool/Default.png?m=1265230535g">
    	<link rel="stylesheet" href="http://s2.wp.com/wp-content/themes/pub/wptouch/style.css?m=1265230535g" type="text/css" media="screen">
    	<style type="text/css">
    #headerbar, #wptouch-login {
    	background: #000000 url(http://s2.wp.com/wp-content/themes/pub/wptouch/core/core-images/head-fade-bk.png);
    }
    #headerbar-title, #headerbar-title a {
    	color: #eeeeee;
    }
    #wptouch-menu-inner a:hover {
    	color: #006bb3;
    }
    #catsmenu-inner a:hover {
    	color: #006bb3;
    }
    #drop-fade {
    background: #333333;
    }
    a, h3#com-head {
    	color: #006bb3;
    }
    </style>
    <link rel="alternate" type="application/rss+xml" title="The iPad Preacher » The Color Coded Family Comments Feed" href="http://theipadpreacher.wordpress.com/2010/08/17/the-color-coded-family/feed/">
    <script type="text/javascript">
    /* <![CDATA[ */
    function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();}}}
    /* ]]> */
    </script>
    <link rel="stylesheet" href="http://s0.wp.com/wp-content/themes/h4/global.css?m=1256671583g" type="text/css">
    <script type="text/javascript" src="http://s1.wp.com/wp-includes/js/jquery/jquery.js?m=1273512554g&ver=1.4.2"></script>
    <script type="text/javascript" src="http://s2.wp.com/wp-content/themes/pub/wptouch/core/core.js?m=1265230535g&ver=1.9"></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://theipadpreacher.wordpress.com/xmlrpc.php?rsd">
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://theipadpreacher.wordpress.com/wp-includes/wlwmanifest.xml"> 
    <link rel="index" title="The iPad Preacher" href="http://theipadpreacher.wordpress.com/">
    <link rel="prev" title="Scripture Only" href="http://theipadpreacher.wordpress.com/2010/08/11/scripture-only/">
    <meta name="generator" content="WordPress.com">
    <link rel="canonical" href="http://theipadpreacher.wordpress.com/2010/08/17/the-color-coded-family/">
    <link rel="shortlink" href="http://wp.me/pW5BZ-j">
    <link rel="shortcut icon" type="image/x-icon" href="http://1.gravatar.com/blavatar/dec3f79c89c8c6b52a21ba8b51cb34a3?s=16&d=http://s2.wp.com/i/favicon.ico" sizes="16x16">
    <link rel="icon" type="image/x-icon" href="http://1.gravatar.com/blavatar/dec3f79c89c8c6b52a21ba8b51cb34a3?s=16&d=http://s2.wp.com/i/favicon.ico" sizes="16x16">
    <link rel="apple-touch-icon" href="http://0.gravatar.com/blavatar/2fd23e2658b1a077fd66fbdfff371a62?s=158&d=http://s0.wp.com/wp-content/themes/h4/i/webclip.png">
    	<style type="text/css">
    	/* <![CDATA[ */
    				div#likes { margin-top: 15px; }
    		.like-button { border: 1px solid #eee; padding: 2px 6px; font-size: 13px; font-family: arial, tahoma, sans-serif; }
    		#wpl-likebox { clear: left; font-size: 11px; font-family: arial, tahoma, verdana, sans-serif !important; min-height: 30px; margin: 10px 0 !important; padding: 5px 0 10px 0 !important; }
    		#wpl-button { float: left; background: url( /i/buttonbg.png ) top left repeat-x; margin-right: 7px; border: 1px solid #d4d4d4; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
    		#wpl-button a { color: #666 !important; line-height: 130% !important; text-decoration: none !important; outline: none; float: left; padding: 3px 6px 2px 24px !important; font-size: 11px !important; background: url( /i/likestar.png ) 6px 49.8% no-repeat; }
    		#wpl-button.liked { background: #feffce; border: 1px solid #f3e389; }
    		#wpl-button.liked a { color: #ba871b !important; }
    		#wpl-likebox #wpl-count { min-height: 25px; line-height: 130% !important; float: left; padding-top: 4px; }
    		#wpl-likebox #wpl-avatars { clear: left; max-height: 98px; overflow: hidden; margin-top: 15px; line-height: 130% !important; }
    		#wpl-likebox #wpl-avatars img { border: none !important; }
    	/* ]]> */
    	</style>
    	<link rel="openid.server" href="http://theipadpreacher.wordpress.com/?openidserver=1">
    <link rel="openid.delegate" href="http://theipadpreacher.wordpress.com/">
    <link rel="search" type="application/opensearchdescription+xml" href="http://wordpress.com/opensearch.xml" title="WordPress.com">
    <link rel="search" type="application/opensearchdescription+xml" href="http://theipadpreacher.wordpress.com/osd.xml" title="The iPad Preacher">
    <script type="text/javascript"> 
    	window.google_analytics_uacct = "UA-52447-2"; 
    </script>
    
    <script type="text/javascript">
    	var _gaq = _gaq || [];
    	_gaq.push(['_setAccount', 'UA-52447-2']);
    	_gaq.push(['_setDomainName', 'wordpress.com']);
    	_gaq.push(['_initData']);
    	_gaq.push(['_trackPageview']);
    
    	(function() {
    		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    	})();
    </script><script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
    	
    <script language="javascript">
    function SetCookie(cookieName,cookieValue,nDays) {
    	var today = new Date();
    	var expire = new Date();
    	if (nDays==null || nDays==0) nDays=1;
    	expire.setTime(today.getTime() + 3600000*24*nDays);
    	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
    }
    var browser_width=jQuery(window).width();
    SetCookie('browser_width',browser_width,1);
    </script>
    <style type="text/css">
    	#headerbar {
    		background: url(?w=300 ) no-repeat left top;
    			}
    </style>
    <!-- stuff -->
    <script type="text/javascript" src="http://s0.wp.com/wp-includes/js/comment-reply.js?m=1231878779g&ver=20090102"></script>
    <meta name="generator" content="WordPress.com">
    <!-- end stuff -->
    </head><body class="classic-wptouch-bg">
    <!-- New noscript check, we need js on now folks -->
    <noscript></noscript>
    
    <!--#start The Login Overlay -->
    	<div id="wptouch-login">
    		<div id="wptouch-login-inner">
    			<form name="loginform" id="loginform" action="http://theipadpreacher.wordpress.com/wp-login.php" method="post">
    				<label><input type="text" name="log" id="log" onfocus="if (this.value == 'username') {this.value = ''}" value="username"></label>
    				<label><input type="password" name="pwd" onfocus="if (this.value == 'password') {this.value = ''}" id="pwd" value="password"></label>
    				<input type="hidden" name="rememberme" value="forever">
    				<input type="hidden" id="logsub" name="submit" value="Login" tabindex="9">
    				<input type="hidden" name="redirect_to" value="/2010/08/17/the-color-coded-family/">
    			</form>
    		</div>
    	</div>
    	
    <div id="headerbar">
    	<div id="headerbar-title">
    		<!-- This fetches the admin selection logo icon for the header, which is also the bookmark icon -->
    						<a href="http://theipadpreacher.wordpress.com">The iPad Preacher</a>
    			</div>
    	<div id="headerbar-menu">
    		    <a href="#" onclick="bnc_jquery_menu_drop(); return false;"></a>
    	</div>
    </div>
    
    <!-- #start The Search / Menu Drop-Down -->
    	<div id="wptouch-menu" class="dropper"> 
     		<div id="wptouch-search-inner">
    			<form method="get" id="searchform" action="http://theipadpreacher.wordpress.com/">
    			<input type="text" value="Search…" onfocus="if (this.value == 'Search…') {this.value = ''}" name="s" id="s"> 
    				<input name="submit" type="hidden" tabindex="5" value="Search">
    			</form>
    		</div>
            <div id="wptouch-menu-inner">
    			<ul>
    				<li><a href="http://theipadpreacher.wordpress.com"><img class="pageicon" src="http://0.gravatar.com/blavatar/2fd23e2658b1a077fd66fbdfff371a62?s=32&d=http://s2.wp.com/wp-content/themes/pub/wptouch/images/icon-pool/Default.png" alt="pageicon">Home</a></li>
    			<li><a href="http://theipadpreacher.wordpress.com/about/"><img class="pageicon" src="http://s2.wp.com/wp-content/themes/pub/wptouch/images/icon-pool/Default.png?m=1265230535g" alt="pageicon">About</a></li><li><a href="http://theipadpreacher.wordpress.com?archives-list=1"><img class="pageicon" src="http://s2.wp.com/wp-content/themes/pub/wptouch/images/icon-pool/Archives.png?m=1265230535g" alt="pageicon">Archives</a></li>			</ul>
            </div>
    	</div>
    
    <!-- #start the wptouch plugin use check -->
    
    <div class="content" id="content3a59b5eee61878ea5862215495837f2a">
    					<div class="post">
    			    <a class="sh2" href="http://theipadpreacher.wordpress.com/2010/08/17/the-color-coded-family/" rel="bookmark" title="Permanent Link to The Color Coded Family">The Color Coded Family</a>
    			        <div class="single-post-meta-top">August 17, 2010 @ 3:50 pm › tbrass84<br>
    
    		<!-- Let's check for DISQUS... we need to skip to a different div if it's installed and active -->		
    									<a href="#respond">↓ Leave a comment</a>
    							</div>
    		<div class="clearer"></div>
    	</div>
    
             <div class="post" id="post-19">
             	<div id="singlentry" class=" full-justified">
                	
    <script type="text/javascript"><!--
    window.googleAfmcRequest = {
     client: "ca-mb-pub-3443918307802676",
     ad_type: "text_image",
     output: "html",
     channel: "3890502655",
     format: "320x50_mb",
     oe: "utf8",
     color_border: "336699",
     color_bg: "ffffff",
     color_link: "0000ff",
     color_text: "000000",
     color_url: "008000",
    };
    //--></script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script><div align="center"><iframe name="google_ads_frame" width="320" height="50" id="google_ads_frame" src="http://googleads.g.doubleclick.net/pagead/ads?channel=3890502655&oe=utf8&ad_type=text_image&client=ca-mb-pub-3443918307802676&color_bg=ffffff&color_border=336699&color_link=0000ff&color_text=000000&color_url=008000&correlator=1283921606703&dt=1283921606703&ea=0&flash=0&format=320x50_mb&frm=1&js=afmc-v1.1&output=html&ref=http%3A%2F%2Fwww.apple.com%2F&u_ah=460&u_aw=320&u_cd=32&u_h=480&u_w=320&u_his=1&u_tz=-360&url=http%3A%2F%2Ftheipadpreacher.wordpress.com%2F2010%2F08%2F17%2Fthe-color-coded-family%2F&dtd=1" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" style="position:relative" align="center"></iframe></div>
    <p>I had an interesting and fun couple of days this past weekend.  ...{clipped}...</p>
    ...
    
     
  23. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #23
    I have no idea how to view the source for the mobile version on my computer.
     
  24. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #24
    document.documentElement.outerHTML
     
  25. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #25
    When I do that, I get the entire HTML for the page. It shows the login bars, advertisements, everything.
     
Thread Status:
Not open for further replies.

Share This Page