I have a custom search engine on a non-wordpress page. This search engine searches a database for a city (specified by a text input) and then returns the relevant information about that city and displays it on the page.
What I want to do now, is to below those results, display the results of a wordpress search of the same term on a blog that resides on the same server/domain. So basically I want to show the same results that a wordpress search of that keyword would return, but I want to display them on a non-wordpress page, not in the blog's theme.
What I have:
a variable holding a search term, the search term has already been shampooed and conditioned to be search engine friendly.
What I don't want to do
I don't want to use an iframe and have the blog template be displayed on the page.
I can't have a secondary search box. I need to somehow use the value of the variable that I have, I can't ask the user to submit a second form or anything.
My ideas so far
Is there a way to run the wordpress search function and grab the data that it returns? I've gotten as far as including wp_blog_header.php on my static page so that I can make use of the wordpress functions.
Or would it be better to write a function that duplicates what the wordpress search does on the wordpress databases, but returns the data in a way that I can use?
Or is there a different approach that I should take for this that I've overlooked? Thanks!
You must first include the Wordpress files
<?php define('WP_USE_THEMES', false);
require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
then use query_posts and the loop
query_posts('s='.keyword);
while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p>Read more...</p><?php
endwhile;
Related
this is my first time posting on this site so apologies if the question isn't totally appropriate but I'm building a portfolio site for my brother who is a composer and he needs his music library to be able to be checkbox filter-able. The problem is that when I conduct a search with filters, the results show only the excerpt, and not the audio player like I need.
Library page displaying the full posts with audio player
Search results page showing just the post title and nothing else
Also, excuse the sheer crudeness of the site. I just started it this morning... Thanks in advance!
To show the full content you have to use the_content function, in your search.php file replace the following
<?php the_excerpt(); // partial content ?>
with
<?php the_content(); // full content ?>
Also remember. the_excerpt function strips out all HTML tags so it could be a problem, you can read this article.
I have a small network of sites setup with WordPress 3.0's multisite feature. I would like to create another site which pulls certain posts from the various other sites to display. This new 'hub' site would seem like its own separate site to the user (with domain mapping), but its content is coming from the posts from the other sites.
How can I get posts from another site in a WordPress multisite setup? Can I query for posts based on the name of the site? The end result needs to be a collection of posts from the different sites sorted by date.
Thanks for your help.
I had the similar issue where I wanted to get posts from one blog and display it on an other I came up with the following solution which you could modify slightly to meet your needs if needed
<?php
global $switched;
switch_to_blog(2); //switched to 2
// Get latest Post
$latest_posts = get_posts('category=-3&numberposts=6&orderby=post_name&order=DSC');
$cnt =0;?>
<ul>
<?php foreach($latest_posts as $post) : setup_postdata($post);?>
<li>
<?php echo short_title('...', 7); ?>
</li>
<?php endforeach ; ?>
<?php restore_current_blog(); //switched back to main site ?>
I'm also limiting the amount of words which is being out putted if you do not want this feature simple use
$post->post_title;
Hope it helps.
This wouldn't be terribly difficult to set up with direct database calls. You can query posts from any site on the install with the $wpdb object. See Displaying Posts Using a Custom Select Query for information on using a custom database query, but keep in mind that instead of selecting from $wpdb->posts you're going to need to access the specific site table you want posts from. On a default Wordpress 3 install, this would be wp_12_posts where 12 is the site id. The id can be found in the wp_blogs table, or by looking at the ID column in the Sites section of the admin menu.
I have a site whose home page shows a single Wordpress category page. I'm using a custom theme and the index.php file there does a 301 redirect to "mysitename.com/?cat=3". This page is generated with an event calendar plugin and a lot of custom code. It works, but the displayed URL is "mysitename.com/?cat=3" which I'd prefer my visitors not see; I'd rather have the URL be just "mysitename.com", "mysitename.com/index.php", or even "mysitename.com/calendar".
The visitor can view "prev month" and "next month", which result in URLs like "mysitename.com?cat=3&eventDate=2010-07&bt=a" -- still within the same category but with additional parameters in the URL. (I am OK having a more convoluted URL like this shown to my visitors on previous/next month; it's just the initial page URL I'd like to be nicer.)
I've messed around with the permalinks but can't get nice URLs to work correctly that way. Is there an .htaccess way to do this?
In the "permalinks" section under the "Settings" tab, you can add a category base to the categories.
Thus if you have a category base of "category" and a category name "Cool Stuff" with a slug of "cool_stuff"
Your category link would link like this depending on your permalink settings.
http://yoursite.com/category/cool_stuff/
Okay. My Last answer was not base on your "edited question".
If you remove the 301 redirect to "mysitename.com/?cat=3"
you can edit the index.php file.
This will most likely take care of your url issue.
You can edit the loop to show only categories from id: 3
Thus, you will make a querypost for category 3 as follow:
<?php query_posts('showposts=9'); ?>
See Query Post # Wordpress for more info.
Put this before the loop.
The coding may look like this:
<?php query_posts('cat=3'); ?>
<?php if (have_posts()) {?>
<?php while (have_posts()) : the_post(); ?>
<li>
<?php the_title(); ?>
<span style="float: right;"><?php the_time('m/d/y'); ?></span>
</li>
<?php endwhile; }?>
You could use .htaccess to map mywebsite.com/calendar to mywebsite/?cat=3, but WordPress will still look at the original url to find out which category to use, so this will not work.
I suggest you look in the code of the plugin to find out how it gets the current category, and maybe trick it (by an extra call to query_posts('cat=3')) to think we are looking at the url for category 3 (you don't need to display the posts, just do the query). You can even do this on your homepage (but maybe use home.php, not index.php, since the latter is a fallback for other template pages), so you don't need a redirect. But the key is that you need to look at the code of your plugin (can you tell us the name?) to find out how it works.
I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul
I want to implement a business directory in WordPress and I am looking for feedback on the best approach:
I have a categories and a businesses table
Do I create a page for every business together with it's category relationship
Do I create a page and assign it a template?
What are the ups and downs with each approach?
Looking for some answers from people that might of already done this and can speak from experience
I've been looking for a similar thing and found this yesterday... http://www.directorypress.net/
It's not cheap but it looks like it might work.
The nice thing about WordPress is that you can go a few different routes w/ trying to accomplish this.
One route that's worked well for me is to list each business as a post and then create categories and sub-categories to house these businesses. Once this is done, you can create custom templates for either category templates (so if your have a category named 'Food Establishments' and it has the category id of 5, you can create a template named category-5.php and then WordPress will know to look to that template first and then move on to the regular category.php file and so on).
In your category template you can then list out each sub category w/ a function like wp_list_categories(); and call out the children categories from there.
The other option is to still go the route of entering in your businesses as a separate post, filing them under the appropriate categories. But instead of creating a category template, you can create a page template. You'll need to do a few things for this
Pre-prend your template file w/ the necessary template syntax to tell WordPress to look for that as a template file such as:
<?php
/* Template Name: Food Establishments */
?>
Create a page in WordPress using this new template
In your page template create a new query, pointing to this category, such as:
<?php $business_food = new WP_Query( 'cat=5' ); ?><br />
<?php if ( $business_food->have_posts() ) : while ( $business_food->have_posts()) : $business_food->the_post(); ?><br />
<?php the_content(); // and do other stuff here ?><br />
<?php endwhile; endif; ?><br />
There are other options you can do as well, and for those, I would hang out some WordPress user groups to see if you can grab some other ideas.