I'm just starting to play around with SimplePie, and have created a basic test page that will display the results of an RSS feed on a webpage. This works well when testing a handful of pages, but fails silently when trying to view an Apple Forum feed.
https://discussions.apple.com//community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date
Any suggestions on how to troubleshoot this issue?
<?php
require_once('php/autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url(
'https://discussions.apple.com//community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date'
);
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
<html>
<head>
<title>Sample SimplePie Page</title>
</head>
<body>
<div class="header">
<h1><?php echo $feed->get_title(); ?></h1>
<p><?php echo $feed->get_description(); ?></p>
</div>
<?php
foreach ($feed->get_items() as $item):
?>
<div class="item">
<h2><?php echo $item->get_title(); ?></h2>
<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>
</body>
</html>
You're going to kick yourself... I checked the return value of $feed->init() and it was false, so I took out the extra / before "community" in your url and it seems to work.
https://discussions.apple.com/community/feeds/search?q=mathtype&peopleEnabled=true&dateRange=all&rankBy=date
When you use the double / in your browser, it ignores it, but SimplePie does not.
Related
UPDATE: I have just figured it out! I used a full URL (http://localhost/practice/wp-content/themes/cpmock/assets/images/cplogo.png) as the img src and now it works on all pages.
I hope someone can help.
I am creating a wordpress site/theme, from scratch, for the first time.
I have created a header.php file which contains a logo, some nav links and a search bar.
I have created several files/pages, such as; index.php, front-page.php, page-about.php and single.php for example.
Each file/page calls the header.php and displays it. However, only the front-page.php file shows the image.
All files/pages are in the root folder. The image src is the full file path. I don't understand why the image only works in the front-page.php and not the others.
I hope someone can advise why this is. I have included code from header.php, front-page.php and page-about.php.
header.php:
<!DOCTYPE html>
<html <?php language_attributes() ?>>
<head>
<meta charset="<?php bloginfo('charset')?>">
<meta name="description" content="<?php bloginfo('description')?>">
<title><?php bloginfo('name')?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div class="container">
<header class="header">
<a href="http://localhost/practice/"><img src="wp-
content/themes/cpmock/assets/images/cplogo.png" alt="CP Logo"></a>
<div class="search-header">
<?php get_search_form(); ?>
</div>
<?php wp_nav_menu( array(
'theme_location' => 'primary'
) ); ?>
</header>
front-page.php:
<?php get_header(); ?>
<section class="front-page">
<h1>front-page.php</h1>
<p>This is a mock website.</p>
</section>
<?php get_footer(); ?>
page-about.php:
<?php get_header(); ?>
<section class="page-about">
<h1>page-about.php</h1>
<h4>This is my custom about page.</h4>
</section>
<?php get_footer(); ?>
Here are a couple of screenshots. One showing the front-page.php which displays the image. The other of the page-about.php which doesn't show the image.
front-page.php image visible
page-about.php image not visible
You should not type static image URLs like that:
"http://localhost/practice/wp-content/themes/cpmock/assets/images/cplogo.png"
The reason you don't type them like that is that you will have to retype them when you connect to the website to a domain. A better solution would be...
<?php
$imageUrl = get_site_url()."/folder/folder/image.png";
?>
<img src="<?php echo $imageUrl ; ?>" alt="CP Logo">
I am trying to only load the 4 latest posts on my page and I have found a line of code that should work. The problem is that I don't know where to put it.
<?php query_posts('posts_per_page=20'); ?>
This is what I found when I was searching for a solution (although I don't know if this will also work for showing only the 4 newest posts. As you can see I already have 'catname=projecten' on that line and I have no idea how to combine the two.
<?php
query_posts('catname=projecten');
while (have_posts()) : the_post();?>
<div class="col-md-3">
<div class="newsfeed center">
<h1><?php echo get_the_title( $ID ); ?> </h1>
<p>
<?php the_content(); ?>
</p>
</div>
</div>
<?php endwhile;
?>
I hope someone can help me out!
I'd like to answer it, because there are few things need to be corrected. This should do it, and notes below.
<?php
query_posts('category_name=projecten&posts_per_page=4');
while (have_posts()) : the_post(); ?>
<div class="col-md-3">
<div class="newsfeed center">
<h2><?php echo get_the_title(); ?> </h2>
<?php the_content(); ?>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
A few notes:
It's category_name, not catname.
You should not use <h1> for each title, for a better accessibility use <h2> or <h3> etc.
get_the_title( $ID ); the $ID seems not necessary to be there.
Don't wrap the_content(); with <p> it's rich content already, use <div> if you need.
Don't forget to reset the query afterwards.
http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Class_Reference/WP_Query
I override block using these technic https://www.drupal.org/node/1089656.
<div id="<?php print $block_html_id; ?>" class="footer-links-regions <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<div class="g4_20 tgfull">
<?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
<h3<?php print $title_attributes; ?>><?php print $block->subject ?></h3>
<?php endif;?>
<?php print render($title_suffix); ?>
</div>
<!-- CONTENT -->
<div class="g16_20 tgfull mhidden" <?php print $content_attributes; ?> >
<?php print $content ?>
</div>
</div>
Then I added custom link via admin and Custom URL (Link display). I realized that I can see this link inside content (I mean that this link is added to $content). I would like to handle this link and real content separately.
I would like to list out the alphabet on a custom post type archive page, and by clicking on a letter in the alphabet it would link to a url that only displays posts that begin with that particular letter. Not necessarily worried about doing it ajax style or anything. Just a simple url will work.
I have this functionality on a site I developed a couple years ago (http://glenwoodia.com/business-directory/), but that was using a big business directory plugin. With this particular site I'm just using a custom post type with custom fields.
My full loop currently looks like this:
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('orderby=title'.'&order=ASC'.'&showposts=15'.'&post_type=businesses'.'&paged='.$paged);
?>
<div class="content">
<div class="main-area-wide">
<div class="internal-wide">
<div class="navigation-top">
<?php wp_pagenavi(); ?>
</div>
<div class="business-wrapper">
<h1>Business Directory</h1>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="business">
<h3><?php the_title(); ?></h3>
<p><?php $key="address"; echo get_post_meta($post->ID, $key, true); ?><br />
<?php $key="website"; echo get_post_meta($post->ID, $key, true); ?><br />
<strong><?php $key="phone"; echo get_post_meta($post->ID, $key, true); ?></strong></p>
<p><?php $key="short_description"; echo get_post_meta($post->ID, $key, true); ?></p>
</div>
<?php endwhile; ?>
</div>
<div class="navigation-btm">
<?php wp_pagenavi(); ?>
</div>
</div>
</div>
</div>
Sorry, this should be added as a comment, but I don't have the rep to do that. Anyway, I believe this is what you need and best of all it's documented well. I have used it before and found it pretty easy to understand:
http://www.kathyisawesome.com/424/alphabetical-posts-glossary/
Basically the same answer is also posted in Stack Exchange, be sure to scroll down to the EDIT part of the answer as that part explains the using a taxonomy thing that she did in the answer above:
https://wordpress.stackexchange.com/questions/41660/how-to-build-a-directory-with-indexes-in-wordpress/
So i'm quite a beginner, trying to make a custom theme. In a page i want to have a gallery. Uploaded images, made a gallery all fine.
When I view the page it outputs only the shortcode:
[gallery orderby="post_date"]
my page.php file basically has:
<?php $content = get_page( $page_id ) ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>
<?php echo $content->post_content ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I really don't understand how to get this to show correctly, any pointers would be greatly appreciated. Cheers, Matt
get_page returns the raw page data. There are a few ways to do what you want:
BAD WAY:
<?php $content = get_page( $page_id ) ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<?php echo "<h1>".$content->post_title."</h1><br>" ; ?>
<?php echo do_shortcode($content->post_content); ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
do_shortcode() renders all registered shortcode that's found within a given string. In this case, your page's content will have all shortcode rendered before being written to the document. I say this is the "bad" way, only because it doesn't follow the usual Wordpress format. Which leads us to the:
BETTER WAY:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id='content' class='shadow'>
<div id='innercontent'>
<!---page title-->
<h1><?php the_title(); ?></h1><br>
<?php the_content(); ?>
</div>
</div>
<?php endwhile;endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This is what's called "The Loop". It is pretty much the standard for all Wordpress Themes in retrieving all Post or Page Data, as well as running queries against the database.
I would suggest getting to know it, as well as running Wordpress queries to modify the loop using WP Query. This is getting into a more complex area of Wordpress, but it will help you in the longrun with figuring out how to gather up all of the posts and pages you want to retrieve in your theme that aren't provided by Wordpress' globals.
Good luck.