Search / Blog / Pages

WordPress Overview

[display-posts category=”wordpress, wordpress-overview, wordpressmorecheats” category_display=”true” category_display=”post_tag” category_display=”taxonomy_name” image_size=”medium” wrapper=”div” wrapper_class=”display-posts-listing grid” meta_key=”_thumbnail_id” pagination=”true” pagination=”1″]



Functions.php

[display-posts category=”functionsenquehtaccess” category_display=”true” category_display=”post_tag” category_display=”taxonomy_name” include_excerpt=”true” image_size=”medium” wrapper=”div” wrapper_class=”display-posts-listing grid” meta_key=”_thumbnail_id”]






Search Results



How to exclude some categories / types from wordpress search results
https://www.wpbeginner.com/plugins/how-to-exclude-specific-pages-authors-and-more-from-wordpress-search/


Blog



Designer Plugins – at very least good to look at for layout ideas
< ol>
  • Plugins: blog-designer/
  • Plugins: blog-designer-pack/ | Demo
  • Plugins: Blog-designer-for-post-and-widget | Demo
  • Plugins: Wp-blog-manager




  • Archives



    [code language=”css”] /* ////////////////////////////////////////////*/ /* ///////////// Archive Page Changes ////////////////*/ /*//////////////////////////////////////////////////////////////////////////////////*/ /* How to Create a Custom Archives Page in WordPress Please do not confuse the custom archives with archive.php template that comes with most WordPress themes. The archive.php template is used to display monthly, category, tag, author, and other archive pages. Our custom archives page would be a single page that will bring all of your other archives together. Creating a Custom Archives Page Template First thing you need to do is to create a page template for the custom archives page. Simply open a new file in your text editor (i.e Notepad) and name it page-archive.php. Next, Add the following lines of code at the top: */ <?php /* Template Name: Archives */ ?> /* Upload the page-archive.php in your WordPress themes folder, and you have created an Archives page template. Now we need to make sure that this page template matches the design of your site. Copy the content of your page.php file located in your theme’s folder and paste it in page-archive.php. Below is an example of how your page-archive.php file would look like: */ /* <?php /* Template Name: Archives */ get_header(); ?> <div id="primary" class="site-content"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <h2 class="entry-title"><?php the_title(); ?></h2> <div class="entry-content"> <?php the_content(); ?> */ /* Custom Archives Functions Go Below this line */ /* Custom Archives Functions Go Above this line */ /* </div><!– .entry-content –> <?php endwhile; // end of the loop. ?> </div><!– #content –> </div><!– #primary –> <?php get_sidebar(); ?> <?php get_footer(); ?> */ /* Creating a Custom Archives Page in WordPress Now that you have the basic page template ready, you need to create a new custom archives page in WordPress. Go to your WordPress admin panel and add a new page (Pages » New). You can call this page Archives, Library, or anything else that you like. Now look at the meta boxes below the publish button on the right hand side of your screen. You should see a meta box called Page Attributes. Click on the drop down menu below Template and choose Archive as your page template. Save and Publish the page. Select Archives Page Template in WordPress Now you have created a page that uses the archives page template, however it will not show any content. Let’s go ahead and add custom archive page elements such as yearly archives, categories, etc. Adding Monthly Archives with Compact Archives If you look at our custom archives page, then you will notice that we are not using the default monthly archives listing that comes with WordPress. Instead, we are using a plugin called Compact Archives. Note we have adopted this plugin and are now maintaining it. Install and activate this plugin the Compact Archives plugin. After activating the plugin, add the following code in your custom archives page template (page-archive.php): <p><strong>By Date</strong></p> <ul> <?php compact_archive($style=’block’); ?> </ul> It will display your monthly archives like this: Displaying monthly archives one year per row using Compact Archives Adding a List of all Categories Categories summarize the main topics of your website and are the best way to sort your content. See why how we use Categories vs Tags. Since we are using categories as the main way to organize our content, we think it is absolutely crucial to list our category archives. To save space, we are going to display it an inline list. First add this code in your archives page template file: <p><strong>Categories:</strong></p> <ul class="bycategories"> <?php wp_list_categories(‘title_li=’); ?> </ul> <div class="clear"></div> Now we need to style this list, make it appear inline and improve their look. Add this to your theme’s style.css file: ul.bycategories { margin: 0; padding: 0; } ul.bycategories li { list-style: none; list-style-type: none; margin: 0; padding: 0; } ul.bycategories li a { list-style: none; list-style-type: none; margin: 0 20px 15px 0; float: left; background: #eee; color: #464646; padding: 5px 10px; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } ul.bycategories li a:hover{ text-decoration: none; background: #ff6200; color: #fff; } .clear{clear: both;} Your categories will look like this: Displaying in line categories on archives page in WordPress Explore? Redirect Users to a Random Post In our archives page, we have an Explore WPBeginner button. This button redirects users to a random post. The purpose is to allow users to randomly stumble through articles. Learn how to redirect users to a random post in WordPress. While this is all the information that we have on our custom archives page, you can most certainly add more. Let’s look at some of the other things that you can add. Adding a Tag Cloud If you want to display a tag cloud of your most popular tags used on the site, then simply add the following code in custom-archive.php file: <p><strong>Tags Cloud:</strong></p> <?php wp_tag_cloud(); ?> The wp_tag_cloud() function comes with a lot of parameters to adjust the number of tags, maximum and minimum tag sizes, etc. Adding a List of Pages If you want to display a list of all pages on your site, then simply add the following code: <?php wp_list_pages( ‘title_li=’ ); ?> Adding a List of Authors To display the list of authors on the site, simply add the following code: <?php wp_list_authors( ‘exclude_admin=0&optioncount=1’ ); ?> Adding Recent Posts If you want to display a list of your most recent posts, then add this code: <?php wp_get_archives(‘type=postbypost&limit=10’); ?> A comprehensive archives page allows your users to efficiently navigate through your old content. We hope that this article helped you create a custom archives page in WordPress. If you have any questions or suggestions, then please let us know by leaving a comment below. */ [/code]





    https://www.wpexplorer.com/limit-wordpress-search/

    [code language=”css”] /* ////////////////////////////////////////////*/ /* ///////////// Search Changes ////////////////*/ /*//////////////////////////////////////////////////////////////////////////////////*/ /* Include the Search Term on Search Results Pages To do this manually you will need to start by creating a child theme (if you’re not sure how, checkout our guide on how to create a WordPress child theme). Next, create a search.php file in your brand new child theme and copy over the code from your old theme (you can find this by either opening up theme files on your server via FTP, or from your WordPress dashboard under Appearance > Editor > Search.php). Now you can replace the default title in your child theme’s search.php with the following: <h2 class="search-title"> <?php echo $wp_query->found_posts; ?> <?php _e( ‘Search Results Found For’, ‘locale’ ); ?>: "<?php the_search_query(); ?>" </h2> This will display the title with the count of the posts found followed by the term that was searched. So it would look something like “15 Search Results Found For: My Search Query”. Highlight the Search Term in Results Highlight Search Terms Plugin Another thing you might want to do is highlight the search term in the search results. This way, when visitors to your site are presented with search results, their search term is highlighted within the individual results. The plugin Highlight Search Terms serves this role well. It’s simple but can help direct your visitors more specifically to what they’re looking for. 2. Add Suggested Spellings in Case of Typos Relevanssi Better Search Plugin Thanks to the popularity of Google and other search engines, most site visitors expect to see spelling suggestions when they interact with your search function. Adding this feature to your results pages improves the user experience, by helping them find what they’re looking for even if they don’t know how to spell it. With over 100,000 active installs, Relevanssi is one of the most popular WordPress plugins for search. While Search Everything works with WordPress’s default functionality, Relevanssi replaces the search feature altogether. Its free services are perfect for small or personal sites, while the premium version offers amazing functionality for large and multi-site managers. In addition to its suggested spelling feature, this plugin provides an array of options, including the ability to search tags, comments, and categories. 3. Add Suggested Pages to Maintain Interest in Your Site Search & Filter WPSOLR Plugin One of the best ways to use your results pages, aside from providing the searched-for information, is to serve up content that is similar to what users are looking for. If you have ever searched Amazon for a product, you’ve probably seen suggestions for other products based on that search. This method of putting valuable content in front of visitors can boost the amount of time they spend on your site. And by suggesting pages for readers to go to – even if it’s not related to their search query – you can do a lot toward decreasing your bounce rate. If you are looking for search functionality that behaves the way Amazon or eBay does, we recommend the WPSOLR plugin. It will enable you to present related content to searchers, and much more. WPSOLR is another freemium plugin, and provides enterprise-level features that only improve with the purchase of its premium versions. While this plugin can work for most sites, you may want to consider the premium version for e-commerce or large sites in particular. Better Search Plugin Another simple option for this is the Better Search plugin. Once installed, you can insert a heat map for your most popular searches in the form of a widget. This will ensure visitors will be presented with plenty of options for where to go next. 4. Add a Search Box Add Search To Menu Plugin Another way to keep people on your site and engaged in their searches is to add a search box on the search results page if there isn’t one already included in your theme. This is especially helpful if no results are returned and you wish to prompt users to try a different search query. Ans easy way to add a search box is with the free Add Search to Menu plugin – just install and use the plugin settings to customize your search form and results. You can also add a search box directly to any page (via your child theme, as mentioned above) by using the core WordPress function “get_search_form();”. <?php get_search_form( true ); ?> This will display the searchform as defined by the searchform.php theme file or if one doesn’t exist WordPress will output HTML for a standard search form. You can learn more at the CODEX. This will make it so your visitors have no excuses for getting off track on your site. When you’re always steering them back in the right direction, you ensure you’re doing your part to enhance people’s experience on your site. And I can assure you right now, that kind of attention to detail doesn’t go unnoticed or unappreciated. 5. Ajax Your Search Ajax Search Lite Plugin The last option we want to mention today to keep readers engaged with your site is to add Ajax search results so your readers can use a “live” search. The free Ajax Search Lite plugin allows users to search your site with results updated as they type. The plugin includes added options for category filter, Google autocomplete and keyword suggestions. For more options consider upgrading to Ajax Search Pro. The premium version of the plugin adds support for bbPress, BuddyPress, WooCommerce and JigoShop so users can search all of your custom post types. Plus there are features for caching, custom fields, 100+ design themes, 4 layouts and lots more. Limit WordPress Search Results By Category Here are a few methods you can use for limiting your search results by category which can be very useful for sites like WPExplorer.com which has sections such as themes, plugins and the blog. 1. Using A Hidden Input Field In Your Searchform.php This is the method I currently use on WPExplorer.com so when people search the main site they will only get search results from the “WordPress Themes” category. All you need to do is add a hidden input to your searchform.php with an id of “cat” and the category id for the value. A basic searchform.php <form method="get" action="<?php echo esc_url( home_url( ‘/’ ) ); ?>"> <input type="text" size="16" name="s" value="Search" /> <input type="submit" value="Go" /> </form> Add the following to limit to the category with an ID of 5 <input type="hidden" name="cat" id="cat" value="5" /> Full Code <form method="get" action="<?php echo esc_url( home_url( ‘/’ ) ); ?>"> <input type="hidden" name="cat" id="cat" value="5" /> <input type="text" size="16" name="s" value="Search" /> <input type="submit" value="Go" /> </form> 2. Adding A Query Statement To Your Search.php File Another useful method for limiting your search results to specific categories is to add a query to your search.php file right before the if statement. Including Categories To The Search By using positive ID’s in the query you can define which categories you want to show in your search results (show categories with ID’s 1,2 and 3). <?php $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; query_posts( "s=$s&paged=$paged&cat=1,2,3" ); ?> Excluding Categories From The Search Alternatively you can use negative ID’s to exclude certain categories from your search page (exclude the category with an ID of 7) <?php $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; query_posts( "s=$s&paged=$paged&cat=-7" ); ?> Exclude Pages From Your Search Page Below are a couple ways you can limit your search results to exclude pages from the results and show only posts. Using a Function Simply insert the following function to your functions.php file // Remove pages from search results function exclude_pages_from_search($query) { if ( $query->is_main_query() && is_search() ) { $query->set( ‘post_type’, ‘post’ ); } return $query; } add_filter( ‘pre_get_posts’,’exclude_pages_from_search’ ); Using A Conditional In Your Search.php File Another way to remove pages from your search.php file is to insert a conditional in your search.php file right after “while ( have_posts())”. This isn’t recommended if you are using a 3rd party theme because if you update the theme in the future you will lose your edits, if it’s your own custom theme then it’s fine. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); // Exclude pages from the loop if ( is_search() && ( $post->post_type==’page’ ) ) { continue; } ?> Exclude a specific page or pages You can also exclude specific posts/pages from your search results pages on their ID’s by using the following code added in the functions.php file. Simply alter the array of ID’s to include the ID’s of the pages or posts you wish to exclude. // Exclude specific posts/pages from search function exclude_pages_from_search($query) { if ( $query->is_main_query() && is_search() ) { $exclude_ids = array( 7, 19 , 21 ); // Array of the ID’s to exclude $query->set( ‘post__not_in’, $exclude_ids ); } return $query; } add_filter( ‘pre_get_posts’,’exclude_pages_from_search’ ); Limit Search To Post Type One of the reasons to use Port Types in WordPress is because you don’t want these in your feed or main wp loop, that is why they are perfect for things like sliders, testimonials, services…etc. However, your custom posts may still appear in your search results page. 1. Exclude A Custom Post Type From Search Results All you have to do to exclude custom posts from search results is to set the following argument when defining your custom post (more info): ‘exclude_from_search’ => true 2. Using A Hidden Field In The Search Form To Show Only Posts From A Specific Custom Post Type Alternatively you can use a hidden field in your search form the same way you did for limiting categories if you want to set up an advanced search form which will only search through the specified custom post type. <input type="hidden" name="post_type" value="portfolio" /> This extra field would go inside your searchform and you would simply replace where it says “portfolio” with your own custom post type name. This method is great if you have a certain section on your site that uses custom post types and you want users to be able to search through those specific posts only. Changing The Number Of Results Per Page By default WordPress uses the number defined under Settings > Reading (blog pages show at most…) to define how many results appear on the search results page. If you would like to show more, less or infinite results on your search page you can do so using the following code: // Alter search posts per page function myprefix_search_posts_per_page($query) { if ( $query->is_search ) { $query->set( ‘posts_per_page’, ’10’ ); } return $query; } add_filter( ‘pre_get_posts’,’myprefix_search_posts_per_page’ ); This code would go in your functions.php file. Preferably in your child theme if working with a theme from another developer. The code will set your search results to “10” per page. You can change the number to whatever you want. For making your search results unlimited use -1. Advanced/Better Search WordPress by default searches based on any content inside your posts and pages. It would be possible to alter the way the search works via functions but it’s fairly complex so if you want to alter the way the search actually works (what it searches for) you may consider instead using a plugin such as the ‘WP Extended Search” plugin. Click the banner below to check it out or search for it in your WordPress dashboard under Plugins > Add New. */ [/code]

    [display-posts category=”wordpress, wordpress-overview, wordpress-morecheats” category_display=”true” category_display=”post_tag” category_display=”taxonomy_name” image_size=”medium” wrapper=”div” wrapper_class=”display-posts-listing grid” meta_key=”_thumbnail_id” pagination=”true” pagination=”100″]
    Scroll to Top