I want to change the Read More link in WordPress, i have found some tutorials where in the <!-- more --> i can write something else <!-- more Proceed... --> (this did not work).
And in the index.php i should edit <?php the_content('Read More..,'); ?>, but in my index.php there is no Read More text, it looks like this <?php the_content(''); ?>, it is empty and it still shows Read More on posts.
Any other ideas how to change it ?
You can change the
<?php the_content(''); ?>
into whatever you want. So you can make it:
<?php the_content('more Proceed... '); ?>
or whatever you want. "Read more..." is default when you leave it open.
add this block of code in function.php file
// Replaces the excerpt "more" text by a link
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read more... </a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Related
I have met a problem on WordPress site:
None images uploaded as media files are showing. I see they have wrong url like this
<a class="thumbLink" href="http:///wp-content/uploads/2014/10/Joseph-Angharad-11.7.2014-271.jpg" rel="prettyPhoto[gallery1]" title=""><i class="icon-search"></i></a>
I've tried to upload new media files and they get similar url and don't displayed.
In the database it seems ok. I don't see such url in it.
Have you met such a problem? Where to look resolving?
As far as I know it happened before removing a plugin (which was inactive).
I get images via the following code:
// instantiate the controller
if (!function_exists("peTheme")) {
$peThemeClassName = apply_filters('pe_theme_controller_classname','PeTheme'.PE_THEME_NAME);
PeGlobal::$controller =& new $peThemeClassName();
function &peTheme() {
return PeGlobal::$controller;
}
peTheme()->boot();
}
<?php $t =& peTheme(); ?>
<section class="thumbImage">
<img src="<?php echo $t->image->resizedImgUrl($content->get_origImage(),350,0); ?>" alt="" class="fullwidth">
<div class="thumbTextWrap">
<div class="thumbText">
<h3 class="sectionTitle"><?php $content->title(); ?></h3>
<?php
$text = get_the_excerpt();
if (strlen($text) > 40)
$text = substr($text, 0, 40) . '...';
echo '<p>' . $text . '</p>';
?>
<?php while ($slide =& $slider->next()): ?>
<?php $img = $slide->img; ?>
<?php
if ( $first ) {
?>
<a class="thumbLink" href="<?php echo $img; ?>" rel="prettyPhoto['<?php $content->slug(); ?>']" title=""><i class="icon-search"></i></a>
<?php
$first = false;
} else {
?>
<?php
}
<?php endwhile; ?>
</div>
</div>
</section>
It quite silly of me but I didn't disable plugins to check.
The problem was in a Parallelize plugin. It has been disabled and from now media files have right url.
This post may be a little outdated, but I had a similar recent issue so in case it proves useful to anyone:
To start, I had previously changed the Wordpress upload directory by adding the following to the end of wp-config.php
define( 'UPLOADS', ''.'files' );
So all my files are saved in domain.com/files/ After upgrading to Wordpress 4.5, all media files had very wrong url, (with something crazy like .../wp-content/uploads/rootuser/public_html/wp-content/uploads...) I tried reinstalling Wordpress, changing the directory again, disabling plugins, then I found a few posts about the Search & Replace working for some, but still no luck.
Then I found this plugin, Upload Url and Path Enabler and used the following settings that suited my situation:
Store Files: files
Full File URL: http://www.domain.com/files
And presto! All media URLs magically updated and all is working again!
I'm customizing a Wordpress Theme and i have stucked in add a custom class to the "the_excerpt()".
I have searched on the web for this function, but nothing is specific to add a custom class.
Hm, i've tried the "get_the_excerpt", but this one doesn't work (returns nothing).
Anyone knows how to do this?
<?php echo get_the_excerpt(); ?>
Shows the excerpt
<p class="your-class"><?php echo get_the_excerpt(); ?></p>
Shows the excerpt in a div with a class
As far as I'm concern wordpress doesnt provide a solution for this however you can try printing the excerpt using this solutions:
Solution 1: printing the class in the page.
<?php echo '<p class="yourclass">' . get_the_excerpt() . '</p>' ?>;
Link of where i found answer 1
Solution 2: override excert function:
You can override the excerpt function in wordpress functions.php using the following code and pasting in the same file:
function my_custom_excerpt( $excerpt ) {
$post_excerpt = '<p class="yourclass">' . $post_excerpt . '</p>';
return $post_excerpt;
}
add_filter( 'the_excerpt', 'my_custom_excerpt', 10, 1 );
Link where i found answer 2
Conclusion: I prefer using the solution #1 because is cleaner and very understable for someone which will maintain the site.
You can add this code to your functions.php to add the class myclass to the excerpt container:
add_action('the_excerpt','add_class_to_excerpt');
function add_class_to_excerpt( $excerpt ){
return '<div class="myclass">'.$excerpt.'</div>';
}
you don't have to put the_excerpt() inside a p tag, this is going to generate a new p tag contains the excerpt , all you have to do is to put the_excerpt() inside a div tag with your class name.
<div class="post-sumary">
<?php the_excerpt() ?>
</div>
I am building out a site in drupal 7 and running into a ton of problems... very new to drupal here.
I pulled the php call for the logo out of the page.tpl file and put into the header block to be added to all pages. I understand I should probably just leave it in the page.tpl file but thought it made sense to utilize the header block but it is no longer working. can someone explain why this is not working?
here is the code
<div id="logo"><?php if ($logo): ?>
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
<?php endif; ?></div>
It's because the variable $logo is not available in block.tpl.php, it is provided only to page.tpl.php.
You can actually grab the values yourself like this:
$theme_name = 'name_of_theme';
$settings = variable_get('theme_' . $theme_name . '_settings', array());
if (isset($settings['logo_path'])) {
$logo = file_create_url($settings['logo_path']);
}
all what you need, it's additions in template.php this code
function hook_preprocess_region(&$variables) {
$variables['logo'] = theme_get_setting('logo');
$variables['front_page'] = variable_get('site_frontpage', 'node');
}
clear cache
and $logo and $front_page will works good.
How in the WORLD is possible? I swear, I've read the equivalent of 3 encyclopedias to no avail. I've tried solutions within regions, page.tpl.php and blocks. None of them give me what I need... and I know there are so many other people that need this too!
I've come to the conclusion that I want to print out the menu within my page.tpl.php ... so no block solutions, please.
I want to be able to loop through the primary menu links (AND children) and rewrite the output so that there's no default Drupal class tagging. The closest I've found is this example:
<?php if (is_array($primary_links)) : ?>
<ul id="sliding-navigation">
<?php foreach ($primary_links as $link): ?>
<li class="sliding-element"><?php
$href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
print "<a href='" . $href . "'>" . $link['title'] . "</a>";
?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
As you can see, links are being reprinted with a custom UL and LI class ... that's GREAT! However, no children are being printed. How would I extend this code so that all children are a part of the list? NOTE: I don't want the children to only appear on their parent page, they must be present all the time. Otherwise, the drop-down menu I have planned is useless.
I sincerely thank you in advance to lessening my gargantuan headache!
It's hard to affect the output once it's got as far as the page.tpl - you might do better looking for template.php functions.
This is one I used to alter the classes of my primary links:
function primary_links_add_icons() {
$links = menu_primary_links();
$level_tmp = explode('-', key($links));
$level = $level_tmp[0];
$output = "<ul class=\"links-$level\">\n";
if ($links) {
foreach ($links as $link) {
$link = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']);
$output .= '<li class="sublevel">' . $link .'</li>';
};
$output .= '</ul>';
}
return $output;
}
And then in page.tpl.php I just called it like this:
<?php if ($primary_links) :?>
<?php print '<div id="menu">'; ?>
<?php print primary_links_add_icons(); ?>
<?php print '</div>'; ?>
<?php endif;?>
I had to add a <span> to my links for styling, so I overrode theme_links() in includes/theme.inc
You can copy the function to your template.php, rename it to yourthemename_links(), and modify it as needed.
This function outputs the ul, li tags, the drupal_attributes, classes of 'first', 'last', 'active', etc, and affects the menus throughout the site.
You may also want to check out the functions in includes/menu.inc, including theme_menu_local_tasks() and menu_local_tasks(), if you need to output the primary and secondary differently.
MarkLNH
I am trying to pull in a styled sidebar specific to the category. I have the following code which works, but it is pulling in BOTH my new sidebar and the default. What am I doing wrong here?
From category.php
<?php get_sidebar();
if ( in_category('39') ) {
include(TEMPLATEPATH . '/sidebar2.php');
} else {
include(TEMPLATEPATH . '/sidebar.php');
}
?>
<?php get_footer(); ?>
Because you're calling sidebar twice; do this:
<?php
if ( in_category('39') ) {
include(TEMPLATEPATH . '/sidebar2.php');
} else {
include(TEMPLATEPATH . '/sidebar.php');
}
?>
There is a slight problem with the code being provided to you. But as Eimantas suggested, you could simply make a new file called category-39.php which will accomplish the job perfectly, if though for some reason you are still wanting to continue using your category.php file, then here is what you would need to do:
if ( is_category('39') ) {
get_sidebar('2');
} else {
get_sidebar();
}
?>
<?php get_footer(); ?>
The difference between this and the code that you posted is that I have removed
<?php get_sidebar(); ?>
Additionally I have changed in_category to is_category. The reason for this is because when looking at the category page itself using is_category will change on the category list, whereas in_category only looks at the current post and therefore will not change according except when looking at the single.php page.
Example:
in_category will change the sidebar for the following url www.mysite.com/category/stuff/myfirstpost
But it will not change the sidebar for this url www.mysite.com/category/stuff
Simply using is_category will fix this problem.
The next thing would be using
get_sidebar('2');
and
get_sidebar();
get_sidebar(); will run the appropriate wordpress functions related to the sidebar in addition to including sidebar.php.
get_sidebar('2'); on the other hand will run all the appropriate wordpresss functions related to the sidebar while also loading sidebar-2.php.
Hope this helps,
Remove this from your code:
get_sidebar();
otherwise you call this file "sidebar.php" twice...
if you look into wp documentation http://codex.wordpress.org/Function_Reference/get_sidebar
you can do it like that:
<?php
if ( in_category('39') ) :
get_sidebar('two'); //this will include sidebar-two.php
else :
get_sidebar();
endif;
?>
You should create separate template named category-39.php and do common design stuff. WP itself will notice that it should apply this template to category with id=39. No need for if else statements.