Wordpress read more content - wordpress

is it possible by any plugin or code modifications to show different contents on frontpage and on "Read more" click. So, could I make a post which looks different on the frontpage and on the article page, so once someone clicks it shows a different post or content.

Have you tried using the_excerpt?
wordpress codex - the_excerpt();
You can also modify the excerpt read more text which defaults to [...] by adding a filter.
/**
* Filter the excerpt "read more" string.
*
* #param string $more "Read more" excerpt string.
* #return string (Maybe) modified "read more" excerpt string.
*/
function wpdocs_excerpt_more( $more ) {
return 'Custom read more text';
}
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );
The excerpt itself is set within the create/edit post in the admin.
You may need need to show the field in the admin which can be done in the screen options at the top of the create/edit post in the admin.
If you require more freedom than the_excerpt provides, I would suggest using custom meta.

Related

How to create a wordpress widget based on post settings

I would like to create a WordPress plugin/widget that I can add to my post either through the Visual Composer area (widget should be selectable) or simply as a shortcode.
The functionality of this widget is that it should allow me to take the settings of that post as an argument in the main function so that I can change the output of the widget based on what is selected for the post.
For example, I have categories for all my posts and if I have a certain category selected, I want to change the output of the widget based on that.
Does anyone know of a good boilerplate to get me started with this?
Thanks
You can create your own widget using the Widget API or the Shortcode API for shortcodes.
Since you want to change the content shown in your, for instance, widget, based on the current post, in the widget() method (which is the method that prints your widget's content in the frontend) you can add your conditionals or whatever you want to print there.
The $post is available in your widget, so you can use functions like get_post_meta() to retrieve the post's settings if you use custom fields, or any other function like get_the_ID() or has_category().
For example:
/**
* Outputs the content of the widget
*
* #param array $args
* #param array $instance
*/
public function widget( $args, $instance ) {
if ( has_category( 'books' ) ) {
echo 'Hey!, I have the Books category!';
} else {
echo "Hey... I don't.";
}
}

Get setting form wordpress customizer and display in a url

How can I create a custom url like this :
www.my-wordpress-blog.com/?layout=fullwidth
www.my-wordpress-blog.com/?layout=grid
www.my-wordpress-blog.com/?layout=list
See Example what excepted as output,
http://themes.themegoods2.com/letsblog/?layout=fullwidth
http://gleedthemes.com/themes/elora/?layout=2
I tried looking on Google, but no "how to" tutorials show up for anything like this.
How create custom URL
Step:1 Login to admin panel and go to "Appreance->Menu"
Step:2 Use the Custom Links panel to add a custom link to your menu, such as a link to an external website.
Step:3 Simply type in the website URL in the URL field and the menu name in the Link Text field.
Step:4 Click the Add to Menu button when done. Use the same steps outlined previously to adjust the order of the menu item and click the Save Menu button at the top or bottom of the screen to save your changes.
Please refer following for more information,
http://www.templatemonster.com/help/wordpress-add-custom-link-menu.html#gref
How To set Layout page
Add page from page menu
Select a Right side Page attribute select a template from there.
publish page and visit a menu from front side.
Final Solution Suggested By [Sociopath]
Path : wp-content/themes/yourtheme/functions.php
add this code at the end of file.
if( ! function_exists( 'themename_demo_set_the_header_layout' ) ){
/**
* Set the demo header layout from child theme.
* #param unknown_type $header
* #return Ambigous <NULL, string>
*/
function themename_demo_set_the_header_layout( $header = 'layout1' ) {
$header = isset( $_GET['header'] ) ? trim( $_GET['header'] ) : null;
// Add more checking conditions here.
return $header;
}
add_filter( 'themename_set_my_header_layout', 'themename_demo_set_the_header_layout', 10, 1 );
}

Wordpress widget for post specific content in sidebar

I am looking for a wordpress plugin that will allow me to add a paragraph to the sidebar that is specific to the blog post. I would need to be able to add that text when creating the post. Is there something out there like that? I have been unsuccessful in searches.
Thanks
This can be easily solved using Custom Fields, the Text Widget and a Shortcode.
This bit of code goes in the theme's functions.php or, preferable, within a custom plugin.
1) Enable shortcodes for the Text Widget
add_filter( 'widget_text', 'do_shortcode' );
2) Define the shortcode, read comments for details
add_shortcode( 'mytext', 'so_13735174_custom_text_widget' );
function so_13735174_custom_text_widget( $atts, $content = null )
{
global $post;
// $post contains lots of info
// Using $post->ID many more can be retrieved
// Here, we are getting the Custom Field named "text"
$html = get_post_meta( $post->ID, 'text', true );
// Custom Field not set or empty, print nothing
if( !isset( $html ) || '' == $html )
return '';
// Print Custom Field
return $html;
}
3) Add a Text Widget in the desired sidebar.
Leave the title empty and put the Shortcode in the content: [mytext].
4) Now each page or post with a Custom Field named text will have its value printed in the Widget.
5) The $html can get fancy and multiple Custom Fields can be used.
This isn't something that I've ever personally done, but try this.
Summary: You will add the a paragraph using a custom field, then display it in a widget.
Details:
First, make sure custom fields are enabled. Edit a post, then click
the "screen options" at the top right of the page. If "Custom
Fields" isn't checked, check it. You should now see a custom field
area below the post editor.
Come up with a name for your custom field. Perhaps
"extra_paragraph". Now put that in the "name" field in the custom
field area.
Write your paragraph in the "value" field the custom field area.
Install the Custom Field Widget plugin, set it to display this
new "extra_paragraph" field. (widget appears to be untested with newer versions of Wordpress so cross your fingers!)
Now when you write or edit posts you should see this "extra_paragraph" field as an option in the "name" dropdown.

is there a way (plugin) to insert html/css/images ect automatically into every wordpress post?

is there a way (plugin) to insert html/css/images ect.. automatically into every wordpress post? most of my posts are going to be very similar so is there a plugin that will automatically insert the pre written html/css/ ect in every post as opposed to me entering it manually every time.
Thank you in advance ;-)
You can write your own simple function for this, see my example below:
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
global $post_type;
if( $post_type == 'post') { /* Or your custom post type, pages etc. */
$content = 'Your custom HTML/CSS content here';
}
return $content;
}
Place this in functions.php and it will be the default content of every new post/page/custom post type you create.
For a list of available post types, please refer to the Codex
You could use a plugin such as Ad injection, it will allow you to do what you need without having to alter / amend / ad any code to the templates or files

Removing "Continue Reading" from the Excerpt on certain template pages

On the following development site, I have a main Products (custom post type) page:
http://keg.brettatkin.com/products/
I want the "Read More" on this page.
When I click through to a specific product, I'm using the Excerpt as the the basic product description and do not want the "Read More" displayed.
http://keg.brettatkin.com/products/creating-compelling-communication/
I have a custom template for the product description pages. How do I remove the "Read More" from this template page?
Thanks
Brett
Look in your functions.php file of your theme, look for a line that starts with.
add_filter('excerpt_more',
It will have 2 arguments and look similar to
add_filter('excerpt_more', 'new_excerpt_more');
the 2nd argument is the function that prints the "read more" so look for the function in this case 'new_excerpt_more' and return ''; after the function declaration.
function new_excerpt_more()
{
if(is_page('excerpts') return "";
// old code here
}

Resources